Skip to main content
Privy now allows you to natively use smart wallet for a better developer experience. Check out the docs here.

Account abstraction with ZeroDev

ZeroDev is a toolkit for creating ERC-4337-compatible smart wallets for your users, using the user’s EOA as the smart wallet’s signer. This allows you to easily add Account Abstraction features into your app.You can easily integrate ZeroDev alongside Privy to create smart wallets from your user’s embedded or external wallets, allowing you to enhance your app with gas sponsorship, batched transactions, and more!Read below to learn how to configure your app to create smart wallets for all your users!

1. Install the required dependencies from Privy and ZeroDev

In your app’s repository, install the required dependencies from Privy and ZeroDev, as well as the permissionless, and viem libraries:

2. Sign up for a ZeroDev account and get your project ID

Visit the ZeroDev dashboard and sign up for a new account if you do not have one already. Set up a new project for your required chain(s) and retrieve your ZeroDev project ID, as well as your paymaster and bundler URLs for the project.Within this Dashboard, you can also configure settings for gas sponsorship and other ZeroDev features!

2. Configure your app’s Privy settings

First, follow the instructions in the Privy Quickstart to get your app set up with a basic Privy integration.Next, set Add confirmation modals to “off” in your app’s [Embedded wallets] page in the Privy dashboard. This will configure Privy to not show its default UIs when your user must sign messages or send transactions. Instead, we recommend you use your own custom UIs for showing users the user operationss they sign.Lastly, update the config.embeddedWallets.createOnLogin property of your PrivyProvider to 'users-without-wallets'.This will configure Privy to create an embedded wallet for users logging in via a web2 method (email, phone, socials), ensuring that all of your users have a wallet that can be used as an EOA.Your PrivyProvider should then look like:

3. Create a smart account for your user

You’ll now create a smart account for your user, using the Privy embedded wallet (an EOA) as the signer.To do so, when the user logs in, first find the user’s embedded wallet from Privy’s useWallets hook, and get its EIP1193 provider. You can find embedded wallet by finding the only entry in the useWallets array with a walletClientType of 'privy'.
Next, pass the returned EIP1193 provider to the toSimpleSmartAccount method from permissionless to create a SmartAccount. This signer corresponds to the user’s embedded wallet and authorizes actions for the user’s smart account.
Finally, using the SmartAccount from above, initialize a smart account client for the user like so:
The kernelClient is a drop-in replacement for a viem Wallet Client, and requests to the smart account can be made using viem’s API.
You can also store the user’s smart account address on Privy’s user object. See this guide for more.

4. Send user operations (transactions) from the smart account

Now that your users have Kernel (ZeroDev) smart accounts, they can now send UserOperations from their smart account. This is the AA analog to sending a transaction.To send a user operation from a user’s smart account, use the Kernel client’s sendTransaction method.
This is a drop-in replacement for viem’s sendTransaction method, and will automatically apply any smart account configurations (e.g. gas sponsorship) you configure in the middleware before sending the transaction.That’s it! You’ve configured your app to create smart wallets for all of your users, and can seamlessly add in AA features like gas sponsorship, batched transactions, and more. 🎉