How to set up a smart account client
How to set up a smart account client
Once users are authenticated, you can start landing transactions onchain using a Smart Account Client. Setting up a new account client is easy using the useSmartAccountClient
hook!
This extends viem
’s Client, enabling account creation, sending transactions, signing messages, sponsoring gas, and more. It’s also EIP-1193 compliant, so you can swap it in for other web3 providers like window.ethereum
.
Usage
The following sets up a Smart Account Client that will allow you to create a new smart account and send transactions signed by your Alchemy Signer.
The default smart account type is Modular Account V2 — the most cost-effective and advanced smart account option. You can specify other account types with additional configuration.
Note: React hooks only support Alchemy Signer. If you want to use a 3rd party signer, see this guide.
Configuration Options
You can customize your client by specifying additional parameters to change account type, add gas sponsorship, etc. These parameters are optional.
Account Type
We recommend using ModularAccountV2 as it 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.
type
(string) - Defines the smart account type. Options:"ModularAccountV2"
(recommended and default)"LightAccount"
"MultiOwnerLightAccount"
"MultiOwnerModularAccount"
Looking for 7702 support? Learn how to use advanced ModularAccountV2
functionality here.
Note: 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.
Gas Sponsorship
To improve transaction UX, we recommend sponsoring gas for users.
policyId
(string) - Gas Manager Policy ID that enables gas sponsorship within policy limits
See the full guide for gas sponsorship.