Resources
Morpho Docs
Official documentation for Morpho protocol and smart contracts.
Privy Wallets
Privy Wallets are a powerful tool for helping users interact with DeFi.
Getting started with Privy
If you have not set up Privy yet, start by following the Privy React quickstart guide to integrate Privy’s authentication and wallet functionality. Optionally, after completing the React quickstart, integrate viem by following the viem integration guide.Using Morpho Vaults with Privy
Morpho vaults are smart contracts that let users earn yield by depositing assets into automated, yield-optimizing pools. Now we’ll integrate Morpho vaults into the app.Configure and deposit into a Morpho vault
Morpho offers multiple vaults, each with different strategies and underlying assets. You can discover vaults on the Morpho App or via the Morpho API. For this example, we’ll use the Steakhouse USDC Vault on Base:1
1. Configure the vault
2
2. Approve the vault to spend USDC
Use viem’s
encodeFunctionData
to encode the approval, and Privy’s useSendTransaction
to send it:3
3. Deposit USDC into the Vault
Use viem to encode the deposit and Privy’s
useSendTransaction
to fund the vault:Read the vault share balance
Query the vault’sbalanceOf
function to determine how much the user can withdraw.
Withdraw from the Vault
Users have options to withdraw a specific amount of USDC or redeem all shares (full exit).- Withdraw a specific USDC amount
Get real-time vault data
You can fetch live vault information using Morpho’s GraphQL API:Key integration tips
- Always approve first: Users need ERC-20 approval before any deposit.
- Use
deposit()
andredeem()
: These cover most use cases effectively. - Handle decimals correctly: USDC uses 6 decimals, vault shares use 18.
- Check liquidity: During high utilization, withdrawals may be limited.
- Monitor gas: Complex vaults may require more gas for transactions.
Conclusion
With Privy, setting up secure, user-friendly access to Morpho contracts is fast and easy. For advanced use cases, refer to the Morpho Docs, or reach out to us in SlackYour app is now ready to interact with Morpho using Privy embedded wallets!