A developer recipe for building Earn and Borrow products using Privy embedded wallets and Morpho lending markets. Clone, configure, ship.
This is an educational demonstration showcasing integration patterns between Privy and Morpho. It is functional but intended for learning purposes. Do not use in production without security audits, testing, and risk assessment.
- Always exercise caution when interacting with real smart contracts and funds
- Always use minimal amounts
- Never Hardcode any private keys
- Consider professional security audits for production applications
This recipe demonstrates how to build a one-click DeFi lending application combining:
- Privy — Embedded wallet infrastructure for seamless user onboarding
- Morpho — Hyper-efficient lending markets and vault yield optimization
- Multi-chain — Supports Ethereum, Base, Arbitrum, Polygon, Optimism, and more
Browse and deposit into Morpho vaults across chains. Real-time APY, TVL, and position tracking with value transitions on deposit/withdraw.
Browse top 50 markets, supply collateral, borrow assets. Full position simulation with LTV, health factor, liquidation price, and review step before execution.
- Privy wallet authentication (social login, email, or external wallet)
- Multi-vault and multi-market support via Morpho's GraphQL API
- Real-time position simulation with before/after projections
- Input validation with clear disabled reasons
- Review step before wallet execution
- Responsive split-view UI (table + action panel)
- Node.js 20+ and yarn
- Privy App ID from the Privy Dashboard
- Basic DeFi knowledge (ERC-20 tokens, lending markets, vaults)
git clone https://github.com/morpho-org/privy-morpho-recipe.git
cd privy-morpho-recipe
yarn installCreate .env.local:
NEXT_PUBLIC_PRIVY_APP_ID=your_privy_app_idRun the development server:
yarn dev| Component | Purpose |
|---|---|
MarketOperationsModal |
Borrow/repay panel with simulation, validation, and review step |
VaultOperationsModal |
Deposit/withdraw panel with value transitions and review step |
MarketTable |
Top 50 markets by size with rate, utilization, and liquidity |
VaultTable |
Top 20 vaults by TVL with APY breakdown and curator info |
SimulationSummary |
Before/after position projections (collateral, debt, LTV, HF) |
ReviewStep |
Inline transaction review before wallet execution |
| Hook | Purpose |
|---|---|
useMarketPosition |
Borrow position state, simulation, validation, transaction handlers |
useVaultPosition |
Vault deposit/withdraw state, slippage detection, safety checks |
useMarkets / useVaults |
GraphQL data fetching and market/vault selection |
useSmartAccount |
Privy wallet integration for transaction signing |
useTxLifecycle |
Transaction state machine (processing, success, error) |
Morpho GraphQL API → Apollo Client → useMarkets/useVaults hooks
↓
User selects market/vault → useMarketPosition/useVaultPosition hooks
↓
On-chain reads (viem) → Position, oracle price, market data
↓
Simulation engine → Projected LTV, HF, liquidation price
↓
Validation engine → CTA state, disabled reasons
↓
Review step → Wallet execution via Privy
| Library | Purpose |
|---|---|
@privy-io/react-auth |
Wallet authentication and embedded wallets |
@morpho-org/blue-sdk-viem |
Morpho contract ABIs and types |
@apollo/client |
GraphQL data fetching from Morpho API |
wagmi + viem |
Blockchain interactions and contract calls |
framer-motion |
UI animations |
The app already supports multiple chains. To add a new Morpho deployment:
- Add the chain to
CHAIN_ID_MAPinsrc/context/ChainContext.tsx - Add the chain config to
wagmiConfiginsrc/app/providers.tsx - The GraphQL API will automatically include markets/vaults on the new chain
- Gas Sponsorship — Privy paymaster integration for gasless transactions
- Health Monitoring — Server-side position monitoring with Privy server wallets
- Batch - Using smart wallet and batching transactions
- Morpho vaults and markets are subject to smart contract risks
- ERC-20 approvals are scoped to the specific transaction amount
- Input validation prevents unsafe positions (LTV checks, balance checks)
- Health factor simulation warns before liquidation-risk actions
- Always test with small amounts first
MIT License — see LICENSE for details.
Built to demonstrate the power of Privy x Morpho integration.


