DeFiYieldEmbedded Wallet
Overview
This guide shows how to integrate a Morpho vault with CDP embedded 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.
Embedded Wallets
CDP Embedded Wallet overview
What you’ll build
- Authenticate users and create embedded 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:Provider setup
Wrap your app withCDPReactProvider:
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 calldeposit with the amount and receiver address.
morpho.ts
Withdraw
To withdraw, callwithdraw with the amount of underlying USDC to receive:
morpho.ts
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:- Replace
VAULT_ADDRESSwith the target vault’s address - Replace
USDC_ADDRESSwith the vault’s underlying token - Update the
parseUnits/formatUnitsdecimals to match the token.