Account Abstraction with ZeroDev
When using account abstraction in your project to sponsor gas, batch transactions, or any other account abstraction features, you will likely want to get a ZeroDev kernel client to perform these operations.
You can use the @dynamic-labs/zerodev-extension
package to create a ZeroDev kernel client for a wallet.
Here is how you can set up and create a kernel client.
The @dynamic-labs/zerodev-extension
depends on the Viem Extension, so before going through this setup, make sure to have the Viem Extension set up and working. Viem Extension Setup
Setup
Install ZeroDevExtension
Install the @dynamic-labs/zerodev-extension package:
Resolve File Resolution Error (Optional)
When running the ZeroDevExtension in your React Native application, you might encounter an error where Metro cannot resolve the paymasterClient.js
file. This issue occurs because Metro tries to load paymasterClient.js
, but the actual file is named paymasterClient.ts
.
To fix this, you need to customize Metro’s resolver in your metro.config.js
file to handle TypeScript file extensions properly.
Generate metro.config.js for Expo Projects
If you don’t have a metro.config.js
file in your project, you can generate one using the following command:
Customize Metro Resolver
Add the following code to your metro.config.js
file to instruct Metro to resolve .ts
files when it cannot find the corresponding .js
files:
This modification allows Metro to attempt to resolve .ts
files when it fails to find .js
files, which fixes the resolution error for the paymasterClient
file.
Events Polyfill
ZeroDevExtension requires a polyfill for the Node.js events module. You can install the events polyfill using one of the following commands:
Integrate with your Dynamic client
To include the ZeroDev module in your Dynamic client, you need to extend the client with the ZeroDev extension:
Now your setup is complete, and you have the ZeroDev module available in your Dynamic client.
Usage
Now that you have the ZeroDev module in your Dynamic client, you can get the ZeroDev kernel client by using the dynamicClient.zeroDev.createKernelClient
method. Here is an example:
Examples
Batch transaction example
This example demonstrates how you can use a ZeroDev kernel client to perform a batched transaction:
Was this page helpful?