Skip to main content

Overview

Morpho is a decentralized lending protocol that offers optimized yield through curated vaults. This guide shows how to use Magic’s Embedded Wallet to deposit USDC into a Morpho Vault on Base and start earning yield — all from within your application. Morpho Vaults implement the ERC-4626 tokenized vault standard. Users deposit an underlying asset (e.g., USDC), receive vault shares representing their position, and earn yield as the share price appreciates over time.

Prerequisites

Before starting, ensure you have:
  1. A Magic Publishable API Key from your Magic Dashboard
  2. A Base RPC endpoint (e.g., from Alchemy or QuickNode)
  3. USDC on Base in the user’s wallet

How It Works

The deposit and withdrawal flow uses standard ERC-4626 vault interactions:
  1. User authenticates with Magic (Email OTP or Social Login)
  2. Magic SDK creates an Embedded Wallet for the user
  3. User approves USDC spend for the Morpho Vault
  4. User deposits USDC and receives vault shares
  5. Yield accrues as the vault’s share price increases
  6. User redeems shares to withdraw USDC plus earned yield
Morpho Vaults are non-custodial and permissionless. Deposits and withdrawals can happen at any time — there is no lock-up period.

Setting Up the Client

Initialize Magic and create a viem wallet client connected to Base.
TypeScript

Contract Setup

Define the vault and token addresses along with the minimal ABIs needed for interaction.
TypeScript
The vault address above is an example. Query the Morpho API or visit app.morpho.org to find the vault that best fits your use case.

Depositing USDC

Depositing requires two transactions: an ERC-20 approval followed by the vault deposit.
TypeScript

Checking Position & Yield

Query the user’s vault shares and convert them to the underlying USDC value to show earned yield.
TypeScript

Withdrawing

Redeem vault shares to withdraw USDC plus any earned yield.
TypeScript

Fetching Vault Data

Use Morpho’s GraphQL API to query available vaults, APYs, and TVL.
TypeScript

Contract Addresses

Key addresses on Base (chain ID 8453):
TypeScript
Individual vault addresses change as new vaults are deployed by curators. Use the Morpho API or browse app.morpho.org to find current vaults.

Key Dependencies


Troubleshooting

Symptoms: The deposit call fails or reverts on-chain.Solutions:
  • Ensure the USDC approval was confirmed before depositing
  • Check that the user has sufficient USDC balance on Base
  • Verify the vault address is correct and the vault is active
  • Some vaults have deposit caps — check if the vault is full
Symptoms: The approve transaction succeeds but deposit still fails.Solutions:
  • Confirm the approval amount is greater than or equal to the deposit amount
  • Wait for the approval transaction receipt before calling deposit
  • Check that you’re approving the correct token (USDC, not USDbC)
Symptoms: User has vault shares but convertToAssets returns zero.Solutions:
  • Ensure you’re querying the correct vault contract
  • The vault may have just been created — share price starts at 1:1
  • Check the vault on app.morpho.org for current state
Symptoms: Redeem or withdraw reverts.Solutions:
  • The vault’s assets may be fully allocated to markets — try a smaller amount
  • Check previewRedeem() to see the maximum withdrawable amount
  • Wait for market utilization to decrease, or try again later

Resources

Morpho Yield Demo

Complete Next.js app with Magic + Morpho on Base

Morpho Documentation

Official Morpho protocol documentation

ERC-4626 Standard

The tokenized vault standard used by Morpho Vaults

Morpho App

Browse vaults, check APYs, and explore the protocol