Skip to main content

Overview

This guide shows how to integrate a Morpho vault with CDP user wallets so your users can deposit tokens to earn yield and withdraw them, without leaving your application. Morpho vaults are ERC-4626 tokenized wrappers that automatically allocate deposits across multiple Morpho Blue lending markets. This guide uses the Steakhouse USDC vault on Base.

Morpho Documentation

Learn more about Morpho Blue markets, vaults, and protocol mechanics.

Non-custodial Wallets

CDP non-custodial wallet overview

What you’ll build

  • Authenticate users and create user wallets with CDP hooks
  • Deposit USDC into a Morpho vault to earn yield
  • Withdraw USDC from the vault
  • Read a user’s vault position

Prerequisites

  • A CDP project with your domain configured
  • Node.js 24+

Installation

Create a React project and install dependencies:
Install CDP packages and viem:

Provider setup

Wrap your app with CDPReactProvider:
main.tsx

Configuration

Define the vault and token addresses, and a public client for reading onchain data:
morpho.ts

Deposit

Before depositing, the user must approve the vault to spend their USDC. Then call deposit with the amount and receiver address.
morpho.ts

Withdraw

To withdraw, call withdraw with the amount of underlying USDC to receive:
morpho.ts
To withdraw the entire position, use redeem with all vault shares instead:
morpho.ts

Check position

Read the user’s vault share balance and convert it to the underlying USDC value:
morpho.ts

Using other vaults

This code works with any ERC-4626 Morpho vault. To use a different vault:
  1. Replace VAULT_ADDRESS with the target vault’s address
  2. Replace USDC_ADDRESS with the vault’s underlying token
  3. Update the parseUnits/formatUnits decimals to match the token.
Browse available vaults here.