What We’re Building
A React (Next.js) app that connects Dynamic’s MPC wallets to Morpho’s lending protocol, allowing users to:- Deposit assets into Morpho vaults
- Track yields and positions
- Claim MORPHO token rewards
- Manage deposits and withdrawals
Key Components
- Dynamic MPC Wallets - Embedded, non-custodial wallets with seamless auth
- Dynamic Transaction Simulation - Built-in transaction preview showing asset transfers, fees, and counterparties before execution
- Morpho GraphQL API - Fetching vaults, vault data, positions, etc.
- Morpho Protocol - Lending protocol with peer-to-peer matching
- ERC-4626 Vaults - Standardized deposit/withdrawal interface
- Rewards System - MORPHO token distribution for liquidity providers
Building the Application
Project Setup
Start by creating a new Dynamic project with React, Viem, Wagmi, and Ethereum support:- Next.js app
- Dynamic SDK with Ethereum wallet connectors
- Wagmi for blockchain interactions
- Viem for transaction handling
- React Query for data fetching
- All necessary dependencies and configurations
Configure Dynamic Environment
Create a.env.local
file with your Dynamic environment ID:
.env.local
Enable Transaction Simulation
Dynamic provides built-in transaction simulation that enhances user experience by showing detailed transaction previews before execution. This feature displays:- Asset Transfers - Clear breakdown of tokens being sent and received
- Network Fees - Estimated gas costs and total transaction cost
- Counterparties - Contract addresses and their verification status
- Transaction Details - Complete transaction information for user review
- Go to your Dynamic dashboard
- Navigate to Developer Settings → Embedded Wallets → Dynamic
- Enable “Show Confirmation UI” and “Transaction Simulation” toggles


Set Up Contract ABIs
Create the necessary ABI files insrc/lib/ABIs/
:
- ERC20_ABI.ts - Standard ERC20 token interface
- ERC4626_ABI.ts - ERC-4626 vault interface for deposits/withdrawals
- REWARDS_ABI.ts - Morpho rewards distributor interface
- MORPHO_MARKETS_ABI.ts - Core Morpho markets contract interface
Configure Constants
Set up your contract addresses and network configuration insrc/lib/constants.ts
:
constants.ts
as const
assertion ensures type safety by making the objects immutable. Vault addresses and token addresses are fetched dynamically from the Morpho GraphQL API.
Create Custom Hooks
Build the custom hooks for data management. Start withuseVaultsList.ts
:
useVaultsList.ts
Build Vault Detail Hook
CreateuseVaultDetail.ts
for fetching individual vault information:
useVaultDetail.ts
Build Vault Operations Hook
CreateuseVaultOperations.ts
for deposit/withdraw functionality:
useVaultOperations.ts
VaultInfo
object that contains the dynamic vault and asset information. It uses the asset’s decimals from the vault data, making it work with any token type. The convertToAssets
function is used to calculate the actual deposited assets from vault shares. It returns a couple of very important values and functions that we use in the vault detail page such as handleApprove
, handleDeposit
, handleWithdraw
, allowance
, assetBalance
, and vaultBalance
.
When users interact with these functions, Dynamic’s transaction simulation will automatically show a detailed preview of the transaction, including the exact amount of assets being deposited or withdrawn, estimated gas fees, and the vault contract address they’re interacting with. This provides transparency and security for all DeFi operations.
Build Vault List Page
Create the main vault discovery page insrc/app/earn/page.tsx
:
page.tsx

Create Vault Detail Page
Build the individual vault page insrc/app/earn/[vaultId]/page.tsx
:
[vaultId]/page.tsx
convertToAssets
function from the ERC4626 standard.

Add Rewards Integration
Create the rewards hook insrc/lib/hooks/useRewardsData.ts
:
useRewardsData.ts
Run the Application
Start the development server:http://localhost:3000
.