Using Compass API with ZeroDev Smart Accounts
This guide demonstrates how to integrate Compass API SDK with ZeroDev to create and use smart accounts for DeFi operations. The combination enables:- Account abstraction features
- Gas fee abstraction (pay in any token)
- Simplified DeFi operations
- Enhanced security through smart account features
Prerequisites
1
Install Dependencies
Install the required packages:
bash npm install @compass-labs/api-sdk @zerodev/sdk @zerodev/ecdsa-validator viem
2
Set Environment Variables
Create a
.env
file in your project root: bash # .env ZERODEV_RPC="your_zerodev_rpc_url" PRIVATE_KEY="your_private_key" COMPASS_API_KEY="your_compass_api_key"
Implementation Guide
1
Import dependencies and initialize clients
First, import the necessary dependencies, load your environment variables, and initialize the public client and entry point.
2
Create signer, validator, kernel account, and paymaster
Set up the signer, ECDSA validator, kernel account, paymaster, and kernel
client. This step prepares your smart account for batched DeFi operations.
3
Create and prepare batched operations
Use the Compass API SDK to create batched DeFi operations (e.g., allowance
increase and Aave supply). Convert the result to the format expected by the
kernel client.
4
Send batched operations and handle result
Send the batched user operation and wait for confirmation. The script will print the transaction hash and confirmation receipt, or an error if the operation fails.