Skip to main content
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.
2

Set Environment Variables

Create a .env:

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.

Compass API Docs

API reference and guides

GitHub Example

View the repository