In this example, we set the USDC spending allowance for a Morpho vault, then perform a deposit.
Notes
  • Amounts are in the token’s smallest units (USDC has 6 decimals). 1 = 0.000001 USDC.
  • Use the correct vault address for your asset.
  • You need a bit of ETH on Base for gas and some USDC for the deposit.
  • Full source code is available in our public GitHub repository: CompassLabs/api_usecases – deposit_on_morpho.

Prerequisites

1

Install Dependencies

Install the required packages.
npm install @compass-labs/api-sdk viem dotenv
2

Set Environment Variables

Create a .env:
# .env
COMPASS_API_KEY="your_compass_api_key"
PRIVATE_KEY="your_wallet_private_key"
WALLET_ADDRESS="0xYourEOA"
SPECIFIC_MORPHO_VAULT="0xVaultAddress"   # the vault that accepts USDC
BASE_RPC_URL="https://base-mainnet.example"  # from your RPC provider

Implementation

Set a USDC allowance and deposit into a Morpho vault.
1

Import Libraries & Environment Variables

2

Initialize SDK and Account

3

Build allowance transaction

Approve the vault to spend your USDC (smallest units).
4

Send allowance

5

Build deposit transaction

6

Send deposit

Full Code


Troubleshooting (quick)

  • Revert or underflow: Check amount units and token decimals.
  • Allowance errors: Ensure the vault address matches the USDC vault.
  • Insufficient funds: Top up ETH on Base for gas.
  • Wrong network: Confirm your RPC URL is Base mainnet.