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:- A Magic Publishable API Key from your Magic Dashboard
- A Base RPC endpoint (e.g., from Alchemy or QuickNode)
- USDC on Base in the user’s wallet
How It Works
The deposit and withdrawal flow uses standard ERC-4626 vault interactions:- User authenticates with Magic (Email OTP or Social Login)
- Magic SDK creates an Embedded Wallet for the user
- User approves USDC spend for the Morpho Vault
- User deposits USDC and receives vault shares
- Yield accrues as the vault’s share price increases
- 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
Depositing USDC
Depositing requires two transactions: an ERC-20 approval followed by the vault deposit.- Approve & Deposit
- With Slippage Check
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.- Full Withdrawal
- Partial Withdrawal
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
Deposit transaction reverts
Deposit transaction reverts
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
Approval not working
Approval not working
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)
Shares show zero value
Shares show zero value
Withdrawal fails with insufficient liquidity
Withdrawal fails with insufficient liquidity
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