List Earn vaults, show a wallet’s position, deposit, withdraw, and claim rewards.
Prerequisites
Before this page: a connected or embedded wallet on the chain of each vault you offer (see Connecting external wallets). Earn vault actions run on EVM and Solana, so EVM vaults need an EVM wallet and Solana vaults need a Solana wallet.React Native calls the same Earn functions as the web, and @dynamic-labs-sdk/react-hooks works there too, so the examples below carry a React Native tab wherever the surrounding component differs. Two things to have in place first: the extension for each chain you offer vaults on registered on the client, which is addEvmExtension for EVM vaults and addWaasSolanaExtension from @dynamic-labs-sdk/solana/waas for Solana vaults with an embedded wallet, and React Native Setup finished, which covers the metadata.universalLink an embedded wallet signs through.
On React Native, use addWaasSolanaExtension rather than addSolanaExtension. addSolanaExtension also registers Wallet Standard wallets, and the @wallet-standard/app package it loads crashes the Hermes engine.
What you’ll build
An Earn flow has four parts:
List vaults and show their APY and curator.
Show a wallet’s position (shares and asset value) in a vault.
Deposit / withdraw: sign and submit from the user’s wallet.
Rewards: show accrued rewards and claim them, for vaults whose provider supports rewards.
Amounts you pass to depositToYieldVault and withdrawFromYieldVault are human-readable ('10.5' for 10.5 USDC). Amounts the SDK returns (shares, assets, accrued) are raw on-chain units, so divide by assetDecimals from getYieldDetails before displaying them.
Listing vaults
listYieldVaults returns every vault the current environment can see, each with a best-effort netApy and tvlUsd.
TypeScript
React
React Native
import { listYieldVaults } from '@dynamic-labs-sdk/client';async function loadVaults() { const vaults = await listYieldVaults(); // renderVaultList is your implementation. renderVaultList(vaults);}
Every vault has a chainName, and the wallet account you pass to the other Earn functions must come from the same chain family. An EVM vault takes an EVM wallet account, and a SOL vault takes a Solana wallet account. The API rejects a wallet account from the other family with an HTTP 400 error, so pick the account from the vault instead of from whichever wallet is active.
getYieldPosition reports the position the API has indexed, which can trail a deposit or withdrawal that is already mined. Treat a position that has not moved yet as “not indexed” rather than “did not happen”: poll it for a bounded number of attempts after a write, and drive your success state off the transaction hash the write resolved with. Pair it with getYieldDetails to format shares/assets — both are raw units, scaled by assetDecimals.
TypeScript
React
React Native
import { getYieldDetails, getYieldPosition, type WalletAccount } from '@dynamic-labs-sdk/client';import { formatUnits } from 'viem';async function loadPosition(vaultId: string, walletAccount: WalletAccount) { const [details, position] = await Promise.all([ getYieldDetails({ vaultId }), getYieldPosition({ vaultId, walletAccount }), ]); return formatUnits(BigInt(position.assets), details.assetDecimals);}
After a deposit or withdrawal, refetch on an interval until the value moves instead of once, so the screen does not show a stale balance for a transaction the chain has already accepted.
Showing earnings and performance
getYieldPerformance reports what a wallet has earned in one vault: netEarningsAssets in the vault asset’s raw units, and returnOnCapital as a fraction, which is null when the provider has no cost basis for the position. getYieldEarnings aggregates every Earn position the wallet holds on one chain into totalAssetsUsd and totalPnlUsd, with a per-vault breakdown in vaults. Earnings are aggregated per chain, so it takes a chainId, which you can read from the vault. Both come from the provider’s index, so they trail the chain the same way the position does.
Pass the YieldVaultSummary from useListYieldVaults, which carries the chainId that useGetYieldEarnings needs. Like the position hook, useGetYieldPerformance and useGetYieldEarnings stay disabled until walletAccount is defined.
import { type WalletAccount, type YieldVaultSummary } from '@dynamic-labs-sdk/client';import { useGetYieldDetails, useGetYieldEarnings, useGetYieldPerformance,} from '@dynamic-labs-sdk/react-hooks';import { Text } from 'react-native';import { formatUnits } from 'viem';function Earnings({ vault, walletAccount,}: { vault: YieldVaultSummary; walletAccount: WalletAccount | undefined;}) { const { data: details } = useGetYieldDetails({ vaultId: vault.vaultId }); const { data: performance } = useGetYieldPerformance({ vaultId: vault.vaultId, walletAccount, }); const { data: earnings } = useGetYieldEarnings({ chainId: vault.chainId, walletAccount, }); if (!details || !performance || !earnings) { return <Text>Loading earnings...</Text>; } return ( <Text> Earned: {formatUnits(BigInt(performance.netEarningsAssets), details.assetDecimals)}{' '} {details.assetSymbol}. PNL on this chain: ${earnings.totalPnlUsd.toFixed(2)} </Text> );}
Depositing
depositToYieldVault takes a human-readable amount and does everything else itself: it requests the signing payload, signs it, and broadcasts it. For an EVM vault, if the wallet’s allowance is short of amount, it signs an ERC-20 approval first, and onStepChange tells you which step is running. A Solana vault has no approval, but a deposit can take up to three transactions, which onTransactionStepChange reports.
TypeScript
React
React Native
import { depositToYieldVault, type WalletAccount } from '@dynamic-labs-sdk/client';async function deposit( vaultId: string, walletAccount: WalletAccount, amount: string,) { const { transactionHash } = await depositToYieldVault({ vaultId, walletAccount, amount, onStepChange: (step) => { // updateStep is your implementation — 'approval' or 'transaction'. updateStep(step); }, }); return transactionHash;}
An embedded wallet signs both steps in a WebView, so keep the screen mounted for the whole deposit. A first deposit into a vault reports approval before transaction, which on a mobile connection is two waits, not one.
Solana vaults take several transactions
A Solana deposit or withdrawal is split into an ordered sequence of up to three Solana transactions. The user approves each one in turn, so a single button press can open more than one wallet prompt. onTransactionStepChange reports { ordinal, total, label } as each transaction begins, which lets you show “Transaction 1 of 2” instead of an unexplained second prompt.
import { depositToYieldVault, type WalletAccount } from '@dynamic-labs-sdk/client';import { SolanaYieldStepError } from '@dynamic-labs-sdk/solana';async function depositToSolanaVault( vaultId: string, walletAccount: WalletAccount, amount: string,) { try { const { transactionHash } = await depositToYieldVault({ vaultId, walletAccount, amount, onTransactionStepChange: ({ ordinal, total }) => { // showProgress is your implementation. showProgress(`Transaction ${ordinal + 1} of ${total}`); }, }); return transactionHash; } catch (error) { if (error instanceof SolanaYieldStepError && error.ordinal > 0) { // Earlier transactions already confirmed. Refetch the position and // let the user decide, instead of repeating the whole deposit. } throw error; }}
Three behaviors matter for the UI:
Keep the user at the screen. The transactions share one blockhash that stays valid only briefly, so a user who takes too long leaves the remaining transactions expired. Tell users to approve every prompt promptly.
A failure can leave the action partly applied. When SolanaYieldStepError.ordinal is greater than zero, the earlier transactions confirmed on-chain. Read the position with getYieldPosition before offering a retry.
The call resolves after confirmation. For a Solana vault, depositToYieldVault and withdrawFromYieldVault resolve only after the last transaction reaches the confirmed commitment level, so you can show success without waiting for a separate receipt.
Gas sponsorship works differently for Solana vaults than for EVM vaults. The SDK sponsors an EVM action by default when your project has EVM gas sponsorship enabled and the wallet is a Dynamic embedded wallet. A Solana action is sponsored only when you pass sponsored: true, so without it the wallet needs a SOL balance to pay network fees. Because sponsored: true rejects when sponsorship is unavailable, and only Dynamic embedded wallets can be sponsored, pass it only when SVM gas sponsorship is enabled for your project and the wallet is an embedded one:
import { depositToYieldVault, type WalletAccount } from '@dynamic-labs-sdk/client';import { isWaasWalletAccount } from '@dynamic-labs-sdk/client/waas';import { isSolanaGasSponsorshipEnabled } from '@dynamic-labs-sdk/solana';async function depositToSolanaVault( vaultId: string, walletAccount: WalletAccount, amount: string,) { // Leave `sponsored` undefined for an external wallet, which signs and pays its own fees. const sponsored = isSolanaGasSponsorshipEnabled() && isWaasWalletAccount({ walletAccount }) ? true : undefined; return depositToYieldVault({ vaultId, walletAccount, amount, sponsored });}
The same sponsored value applies to withdrawFromYieldVault.
Withdrawing
withdrawFromYieldVault is the mirror of deposit, minus the approval step. The wallet is redeeming a position it already holds, so an EVM withdrawal is a single transaction. A Solana withdrawal can take up to three, and it takes the same onTransactionStepChange callback and raises the same SolanaYieldStepError as a Solana deposit.
TypeScript
React
React Native
import { withdrawFromYieldVault, type WalletAccount } from '@dynamic-labs-sdk/client';async function withdraw( vaultId: string, walletAccount: WalletAccount, amount: string,) { const { transactionHash } = await withdrawFromYieldVault({ vaultId, walletAccount, amount, }); return transactionHash;}
Read accrued rewards with getYieldRewards, and only show a claim action once at least one entry has a non-zero accrued amount, because claimYieldRewards rejects when nothing is claimable.Not every provider supports rewards, and today only Morpho does. For a vault from an unsupported provider, such as an Aave vault, getYieldRewards and claimYieldRewards reject with an HTTP 400 error, so check the vault’s provider from listYieldVaults or getYieldDetails and hide the rewards section for it. See Provider support.