Earn component provides a simple interface for earning interest on your crypto via Morpho vaults on Base.
Quickstart
To useEarn, you’ll need to provide a vaultAddress prop. A vault address can be obtained from Morpho’s Vaults page.
Customization
Custom components and layouts
Earn accepts a children prop that can be used to render Earn subcomponents or custom components.
For instance, you can render the EarnDeposit component by itself within the Earn component, along with any other custom components you’d like to render.
For more granular control, you can also render lower level subcomponents within
EarnDeposit and EarnWithdraw. These subcomponents accept className props to customize their styles.
Customizing styles
TheEarn component is best styled via a OnchainKit theme. You can also override individual component styles using className.
Advanced Usage
If you’d like to implement your own custom components, you can useuseEarnContext within an Earn component to access context and build your own components.
You can find the full interface for EarnContextType on the Types page.
Below, we use useEarnContext to implement a custom deposit interface by using useEarnContext to access the depositAmount and setDepositAmount context values.
Taking advantage of the data and methods provided by
useEarnContext, developers can implement fully custom deposit and withdraw interfaces, modifying everything from UI elements to input behavior.
Examples
Sponsoring transactions
To sponsor transactions, you can use theisSponsored prop.
OnchainKitProvider has a paymaster configured:
If you have a contract allowlist set on Coinbase Developer Platform, you’ll need to ensure that the following contract functions are allowed:
depositon the Morpho vaultredeemon the Morpho vaultapproveon the token being deposited
Components
TheEarn component includes the following subcomponents:
<Earn />- A fully built Withdraw and Deposit component. Also includes achildrenprop to render custom components and providesuseEarnContextto access the context values.<EarnProvider />- A headless provider that provides theuseEarnContexthook to theEarncomponent.<EarnDeposit />- A fully built deposit card.<EarnWithdraw />- A fully built withdraw card.<EarnDetails />- A component that displays the details of the vault.<DepositAmountInput />- A component that handles the deposit amount input.<DepositBalance />- A component that displays the balance underlying asset in the user’s wallet.<DepositButton />- A component that triggers the deposit transaction.<WithdrawAmountInput />- A component that handles the withdraw amount input.<WithdrawBalance />- A component that displays how much the user can withdraw from a vault.<WithdrawButton />- A component that triggers the withdraw transaction.<YieldDetails />- A component that displays the yield details of the vault.<VaultDetails />- A component that displays the vault details.
Hooks
useEarnContext- A hook that provides the context values of theEarncomponent.useBuildDepositToMorphoTx- A hook that builds a deposit transaction to Morpho.useBuildWithdrawFromMorphoTx- A hook that builds a withdraw transaction from Morpho.useMorphoVault- A hook that provides the details of a Morpho vault.
Props
EarnProps
EarnProviderProps
EarnContextType
LifecycleStatus