Skip to main content

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 addSolanaExtension for Solana vaults, and React Native Setup finished, which covers the metadata.universalLink an embedded wallet signs through.

What you’ll build

An Earn flow has four parts:
  1. List vaults and show their APY and curator.
  2. Show a wallet’s position (shares and asset value) in a vault.
  3. Deposit / withdraw: sign and submit from the user’s wallet.
  4. 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.

Choosing the wallet for a vault

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.

Showing a wallet’s position

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.

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.

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.
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:
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.

Rewards

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.

Handling errors

See also

Last modified on October 20, 2026