A small, clear example. We set the USDC spending allowance for a Morpho vault, then perform a deposit. Keep it simple. Change only what you must. Test with tiny amounts.
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/python_example.

Prerequisites

1

Install

pip install compass_api_sdk web3 python-dotenv
2

Set environment

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

1

Initialize SDK and Web3

2

Helper to sign and send

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.