Skip to main content

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:
  1. A Magic Secret Key — from your Magic Dashboard
  2. An OIDC Provider ID — configured for your auth provider (setup guide)
  3. A Base RPC endpoint (e.g., from Alchemy or QuickNode)
  4. A user JWT from your authentication provider

How It Works

  1. Your server authenticates the user and obtains a JWT
  2. JWT is sent to Magic’s TEE to get (or create) the user’s EOA
  3. The AAVE SDK generates the supply or withdraw transaction plan
  4. If approval is required, the approval transaction is signed via the TEE and broadcast
  5. The main transaction is signed via the TEE and broadcast
  6. 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 the withdraw 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


TEE Endpoints Used


Troubleshooting

Symptoms: Authentication errors when calling TEE endpoints.Solutions:
  • Verify the JWT token is valid and not expired
  • Check that X-Magic-Secret-Key matches your dashboard credentials
  • Ensure the OIDC Provider ID is correct
  • Confirm your domain is allowlisted in the Magic Dashboard
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)
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.value field for the amount needed
  • Verify the token balance on Base before calling supply
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 executePlan helper 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