Skip to main content

depositToYieldVault

Deposits assets into an Earn vault, then signs and sends the transaction for you. You pass a vaultId and a plain amount like '10.5' — Dynamic looks up the vault’s address and decimal places for you, so you never have to handle those yourself. Before a wallet’s first deposit into a vault, it needs to give the vault contract permission to move its tokens. This is called an approval (or allowance). If the wallet hasn’t approved enough yet, depositToYieldVault signs and sends that approval automatically, before the deposit — onStepChange tells you which of the two is happening so you can reflect it in your UI.

Usage

Parameters

Returns

Promise<{ transactionHash: string }> - The hash of the deposit transaction.

Step Lifecycle

A resolved depositToYieldVault call means the deposit transaction was sent, not that it finished. See Waiting for confirmation before showing a success state to the user.

Waiting for confirmation

transactionHash is returned as soon as the deposit is broadcast to the network — it can still fail or revert after that. Wait for a receipt before telling the user their deposit succeeded:

Examples

With progress UI

This example uses React; the JavaScript SDK is framework-agnostic and can be used with any frontend or in Node.

Supported Chains

depositToYieldVault only supports EVM wallet accounts — vault actions are EVM-only today. Calling it with a non-EVM walletAccount throws a WalletProviderMethodUnavailableError, since only EVM wallet providers implement the underlying executeYieldTransaction method.

React

useDepositToYieldVault invalidates useGetYieldPosition on success, so the position refetches automatically. That refetch can still briefly show the old balance, since the deposit transaction may not be mined yet — see Waiting for confirmation.
Last modified on September 1, 2026