Overview
Aave V3 is a decentralized liquidity protocol where users can supply assets to earn yield and withdraw them at any time. In this guide, we’ll walk through using Turnkey to sign common Aave transactions on Base Mainnet with USDC: approving the Aave Pool to spend USDC, supplying USDC, reading the resulting aUSDC balance, and withdrawing USDC back to the wallet. We’ll also demonstrate Turnkey’s policy engine by restricting signing operations to the specific Aave Pool and USDC contracts on Base. A working example can be found here.Getting started
The first step is to set up your Turnkey organization and account. By following the Quickstart guide, you should have:- A root user with a public/private API key pair within the Turnkey parent organization
- An organization ID
Setting up the policy for the non-root user
Now we’ll use a non-root Turnkey user to sign Aave transactions, while ensuring it can only interact with the USDC token and the Aave Pool contracts on Base mainnet. We’ll define a new API client that would use the organization root user to create the required policy:Set up the Turnkey signer
We’ll be using@turnkey/viem
to create a Turnkey custom signer which implements the signing APIs expected by the viem
client. Notice that the Turnkey API client is going to use the non-root user API key now as using a root user will bypass the policy engine evaluation.