Smart Account Client
The SmartAccountClient
is an extension of viem
’s Client which allows you to interact
with Smart Contract Accounts. You can use the Smart Account Client to send User Operations, sign messages with your account, sponsor gas,
and other account-related actions.
The client is also EIP-1193 compliant, meaning it can easily be swapped out in place of other web3 providers (eg. window.ethereum
).
Account hoisting
If you’re using the React or Core packages, the Smart Account Clients already handle hoisting and creation of account instances. The Smart Contracts package exports client definitions for hoisted instances of the Smart Contract Accounts.
When creating a Smart Account Client, you have two options:
- You can pass an account instance directly into the client constructor. Doing so will use that account for all of the actions you perform with the client, and you won’t have to pass in the account each time you call a method. This is known as “account hoisting”.
- You can create a client without passing in an account. As a result, you’ll have to pass in an account instance to each method you call on the client. This is really useful if you want to manage multiple instances of an account in your app, and want to use one client for all of them.
Let’s see an example:
Smart Account Client actions
Because the Smart Account 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.