Configure client
A smart wallet client is the main interface used to interact with smart wallets and take actions like sending transactions, batching transactions, swapping, sponsoring gas, and more.
How It Works
The SmartWalletClient is a EIP-1193 compatible extension of viem’s Client which allows you to interact with smart wallets.
Prerequisites
Implementation
React
Javascript
API
The useSmartAccountClient hook provides access to your smart account client using the API key and policy ID settings from [createConfig]/docs/wallets/react/quickstart/ui-customization).
React hooks only support Alchemy Signer, so ensure you set up your environment and app integration before using the client.
Don’t call methods like client.sendUserOperation() directly on the client. Instead, use React hooks like useSendCalls which provide better state management and error handling.
Advanced
Override default account type
By default, the Smart Wallet Client will use ModularAccountV2(MAv2). This is the cheapest and most advanced Smart Account, but you can specify other smart contract account types as needed. Learn more about the different smart accounts here.
Changing the account type will deploy a different account. If you’ve already deployed an account for a user and want to change the underlying account type, you’ll need to upgrade it. Learn how to upgrade here.
React and React Native
Override the default account type using the type parameter:
type(string) - Defines the smart account type. Options:"ModularAccountV2"(recommended and default)"LightAccount""MultiOwnerLightAccount"
Javascript
Specify the account type when calling requestAccount using the creationHint parameter. See all parameter options.
API
Pass an accountType to creationHint when calling wallet_requestAccount.
Using 7702
To use EIP-7702, please see this guide. You’ll need to set additional parameters on the client.
Connect to an existing account address
By default, account addresses are deterministically generated from the signer address. To connect to an existing account that doesn’t match the deterministic address of your signer, specify the account address when creating the client.
React & React Native
Javascript
Pass the address to the createSmartWalletClient directly rather than calling requestAccount.
API
Pass the account address directly when preparing calls instead of calling wallet_requestAccount. See this guide and skip step 2.
Extend client with custom actions
Because the Smart Wallet Clients are extensions of viem’s clients, they support extensions via the .extend method. The base client already includes a number of actions by default. You can find additional details about these actions in the @aa-sdk/core documentation.
Use one client for multiple accounts
Typically, the smart account client uses the default account or the account passed into the client constructor for all of the actions you perform with the client - also known as account hositing.
If you want to manage multiple instances of an account but want to use one client for all of them, you can pass an account to the client on every action.