Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.crossmint.com/llms.txt

Use this file to discover all available pages before exploring further.

This guide explains how to supply tokens to Morpho Vaults and earn yield using Crossmint wallets. Morpho is a decentralized lending protocol deployed across multiple EVM chains, offering ERC-4626 compliant vaults that optimize yield across lending markets.

Prerequisites

To use Morpho Vaults with Crossmint wallets, you need:
  • A Crossmint wallet on Base
  • A production API Key with the scope: wallets:transactions.create (create in the Production Console)
This guide uses USDC on Base mainnet as an example. To follow along, you will also need:
  • USDC on Base mainnet in the wallet
  • ETH on Base for gas fees (not required if gas sponsorship is enabled)
You can adapt the code to supply other tokens or use vaults on other chains where Morpho is deployed (Ethereum, Arbitrum, Polygon, and others).

Discover Vaults

Morpho exposes a public GraphQL API for discovering available vaults, their APYs, and total deposits. No API key is required.
const MORPHO_API = "https://api.morpho.org/graphql";

const query = `{
  vaultV2s(
    first: 10,
    where: { chainId_in: [8453], assetAddress_in: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"] },
    orderBy: TotalAssetsUsd,
    orderDirection: Desc
  ) {
    items {
      address
      name
      avgNetApy
      totalAssetsUsd
    }
  }
}`;

const response = await fetch(MORPHO_API, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ query }),
});
const data = await response.json();
const vaults = data.data.vaultV2s.items;

Supply Tokens

High-level steps to supply tokens to a Morpho Vault:
  1. Query the Morpho API to select a vault
  2. Approve the vault contract to spend your tokens (ERC-20 approve)
  3. Deposit tokens into the vault (ERC-4626 deposit)
Morpho Vaults operate on mainnet only. The wallet must hold sufficient tokens on the target chain and ETH for gas fees.
import { useWallet, EVMWallet } from "@crossmint/client-sdk-react-ui";
import { encodeFunctionData, erc20Abi, parseUnits } from "viem";

const USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
const USDC_DECIMALS = 6;
const VAULT_ADDRESS = "0xbeef0e0834849aCC03f0089F01f4F1Eeb06873C9"; // Steakhouse USDC on Base

const vaultAbi = [
    {
        name: "deposit",
        type: "function",
        inputs: [
            { name: "assets", type: "uint256" },
            { name: "receiver", type: "address" },
        ],
        outputs: [{ name: "shares", type: "uint256" }],
        stateMutability: "nonpayable",
    },
] as const;

export function SupplyComponent() {
    const { wallet } = useWallet();

    async function supply(amount: string) {
        if (!wallet) return;
        const evmWallet = EVMWallet.from(wallet);
        const depositAmount = parseUnits(amount, USDC_DECIMALS);

        // 1. Approve the vault to spend USDC
        await evmWallet.sendTransaction({
            to: USDC_ADDRESS,
            data: encodeFunctionData({
                abi: erc20Abi,
                functionName: "approve",
                args: [VAULT_ADDRESS, depositAmount],
            }),
        });

        // 2. Deposit USDC into the Morpho vault
        const tx = await evmWallet.sendTransaction({
            to: VAULT_ADDRESS,
            data: encodeFunctionData({
                abi: vaultAbi,
                functionName: "deposit",
                args: [depositAmount, wallet.address as `0x${string}`],
            }),
        });

        console.log("Supply complete!", tx.hash);
    }

    return (
        <button onClick={() => supply("10")}>Supply 10 USDC</button>
    );
}
See the React SDK reference for more details.

Withdraw Tokens

To withdraw tokens from a Morpho Vault, call the ERC-4626 withdraw function. This redeems your shares and returns the underlying tokens.
import { useWallet, EVMWallet } from "@crossmint/client-sdk-react-ui";
import { encodeFunctionData, parseUnits } from "viem";

const VAULT_ADDRESS = "0xbeef0e0834849aCC03f0089F01f4F1Eeb06873C9";
const USDC_DECIMALS = 6;

const withdrawAbi = [
    {
        name: "withdraw",
        type: "function",
        inputs: [
            { name: "assets", type: "uint256" },
            { name: "receiver", type: "address" },
            { name: "owner", type: "address" },
        ],
        outputs: [{ name: "shares", type: "uint256" }],
        stateMutability: "nonpayable",
    },
] as const;

export function WithdrawComponent() {
    const { wallet } = useWallet();

    async function withdraw(amount: string) {
        if (!wallet) return;
        const evmWallet = EVMWallet.from(wallet);
        const walletAddress = wallet.address as `0x${string}`;

        const tx = await evmWallet.sendTransaction({
            to: VAULT_ADDRESS,
            data: encodeFunctionData({
                abi: withdrawAbi,
                functionName: "withdraw",
                args: [parseUnits(amount, USDC_DECIMALS), walletAddress, walletAddress],
            }),
        });

        console.log("Withdrawal complete!", tx.hash);
    }

    return (
        <button onClick={() => withdraw("10")}>Withdraw 10 USDC</button>
    );
}

Customizing the Vault

The example above uses the Steakhouse Prime Instant USDC vault on Base. You can adapt this to any Morpho vault by:
  1. Changing the vault address — Use the Discover Vaults query to find vaults for different tokens or chains
  2. Changing the chain — Morpho is deployed on Ethereum, Base, Arbitrum, Polygon, and other EVM chains. Update the chainId_in filter and the wallet chain accordingly.
  3. Changing the token — Update the assetAddress_in filter and token decimals to match the vault’s underlying asset

Troubleshooting

Ensure the wallet holds enough of the token to cover the deposit amount.
Verify the approval was confirmed before calling deposit. Check that the vault has not been paused.
Confirm the chain ID and asset address are correct. Some vaults may be delisted.
Vault shares are minted to the receiver address. Verify the wallet address is correct.

Next Steps

Yield Strategies

Learn how vaults generate returns and which strategies fit your users.

Gas Sponsorship

Remove the ETH requirement for gas fees so users only need the supply token.

Morpho SDK

Explore advanced use cases like direct market lending and borrowing.