Overview
This guide shows how to use Magic’s Express Server Wallet to supply USDC to AAVE V3 on Base using the@aave/client SDK. The SDK generates the transaction plan, and your server signs it via the TEE and broadcasts — the private key never leaves the TEE.
Prerequisites
Before starting, ensure you have:- A Magic Secret Key — from your Magic Dashboard
- An OIDC Provider ID — configured for your auth provider (setup guide)
- A Base RPC endpoint (e.g., from Alchemy or QuickNode)
- A user JWT from your authentication provider
How It Works
- Your server authenticates the user and obtains a JWT
- JWT is sent to Magic’s TEE to get (or create) the user’s EOA
- The AAVE SDK generates the supply or withdraw transaction plan
- If approval is required, the approval transaction is signed via the TEE and broadcast
- The main transaction is signed via the TEE and broadcast
- The user receives aUSDC, which accrues interest automatically
TEE Request Helper
All TEE calls use the same authentication headers. Create a reusable helper for your server-side code.TypeScript
Get or Create a Wallet
Fetch the user’s wallet address. If one doesn’t exist, it will be created automatically.TypeScript
Sign and Broadcast Transactions
Build the transaction locally, compute its unsigned hash, sign via the TEE, and broadcast.TypeScript
Setting Up the AAVE Client
Install dependencies and initialize the AAVE client.TypeScript
Executing an AAVE Plan via TEE
The AAVE SDK returns an execution plan that may include an approval step. This helper signs and broadcasts each step through the TEE.TypeScript
Supplying USDC
Use the AAVE SDK to generate a supply plan, then execute it via the TEE.TypeScript
Withdrawing USDC
Use thewithdraw action to pull USDC back from the lending pool, including any earned yield.
TypeScript
Checking Position
Read the user’s aUSDC balance to see their current position including accrued yield.TypeScript
The aUSDC balance increases over time as interest accrues. Unlike vault-based protocols, AAVE’s aTokens are rebasing — the balance itself grows, so
1 aUSDC always equals 1 USDC of underlying value.Key Dependencies
| Package | Purpose |
|---|---|
viem | Ethereum client for transaction serialization and broadcasting |
@aave/client | AAVE V3 SDK for building supply and withdraw transactions |
TEE Endpoints Used
| Endpoint | Purpose |
|---|---|
POST /v1/wallet | Get or create an EOA wallet |
POST /v1/wallet/sign/data | Sign a raw transaction hash |
Troubleshooting
TEE returns 401 or 403
TEE returns 401 or 403
Symptoms: Authentication errors when calling TEE endpoints.Solutions:
- Verify the JWT token is valid and not expired
- Check that
X-Magic-Secret-Keymatches your dashboard credentials - Ensure the OIDC Provider ID is correct
- Confirm your domain is allowlisted in the Magic Dashboard
Supply transaction reverts
Supply transaction reverts
Symptoms: The supply transaction fails or reverts on-chain.Solutions:
- Check that the USDC approval was confirmed before the supply transaction
- Verify the wallet has sufficient USDC balance on Base
- Ensure the wallet has ETH on Base for gas fees
- Confirm the USDC address is correct (native USDC, not bridged USDbC)
SDK returns InsufficientBalanceError
SDK returns InsufficientBalanceError
Symptoms: The
supply action returns a plan with __typename: "InsufficientBalanceError".Solutions:- The wallet doesn’t have enough USDC to supply the requested amount
- Check the
plan.required.valuefield for the amount needed - Verify the token balance on Base before calling
supply
Nonce errors
Nonce errors
Symptoms: Transaction fails with a nonce-related error.Solutions:
- Ensure no concurrent transactions are being sent for the same wallet
- If a previous transaction is pending, wait for it to confirm
- The
executePlanhelper increments the nonce after each step — ensure it’s not called concurrently
Resources
Express API Docs
Learn about Magic’s Express Server Wallet API
AAVE V3 Documentation
Official AAVE protocol documentation
EVM Data Preparation
Guide for preparing EVM transaction data for signing
AAVE Base Markets
View current AAVE supply rates on Base