Learn how to use Compass API SDK with Safe for smart account operations
This guide demonstrates how to integrate Compass API SDK with Safe Starter Kit SDK to create and use smart accounts for DeFi operations.
Install Dependencies
Install the required packages:
Set Environment Variables
Create a .env
file in your project root:
Import dependencies and load environment
First, import the necessary dependencies and load your environment variables.
Create Safe client and initialize Compass API SDK
You have two options for setting up your Safe client:
This step also initializes the Compass API SDK for DeFi operations.
Create and prepare batched operations
Here’s an example of increasing allowance and supplying tokens to Aave. If you are deploying a new Safe, only include the ALLOWANCE_INCREASE
operation in the first transaction. The Safe will not have any tokens initially, so the AAVE_SUPPLY
operation should be executed in a subsequent transaction after funding the Safe with USDC.
Send batched operations and handle result
Convert the operations to the format expected by Safe and execute them. The script will print the transaction result or an error if the wallet is not funded.
Here is the full script from the tutorial. Copy and paste in your code editor and play around!
Here are some examples of different DeFi operations you can perform:
Access detailed API documentation and references
Learn more about Safe’s smart account features
View more code examples and implementations