Skip to main content

withdrawFromYieldVault

Withdraws assets from an Earn vault, then signs and sends the transaction for you. As with depositToYieldVault, you pass a vaultId and a plain amount like '10.5', and Dynamic looks up the vault’s address and decimal places for you. Unlike a deposit, there’s no approval step first: the wallet already owns its position in the vault, so an EVM withdrawal is always a single transaction. A Solana withdrawal is an ordered sequence of up to three transactions. When the wallet’s shares are staked in the vault’s farm, the sequence starts by unstaking them, then withdraws, and then runs any cleanup the vault program needs. withdrawFromYieldVault signs, sends, and confirms each transaction before it starts the next, and onTransactionStepChange reports progress through the sequence.

Usage

Parameters

Returns

Promise<{ transactionHash: string }> - The hash of the withdraw transaction. For a Solana vault, this is the signature of the last transaction in the sequence.
For an EVM vault, a resolved withdrawFromYieldVault call means the withdrawal was sent, not that it finished. See Waiting for confirmation before showing a success state to the user.

Waiting for confirmation

For an EVM vault, transactionHash is returned as soon as the withdrawal is broadcast to the network, and it can still fail or revert after that. Wait for a receipt before telling the user their withdrawal succeeded:

Solana vaults

For a Solana vault, withdrawFromYieldVault polls each transaction until it reaches the confirmed commitment level before it starts the next one, and it resolves only after the last transaction has confirmed. A resolved call therefore means every transaction in the sequence landed, although a confirmed transaction is not yet finalized. All of the transactions in the sequence share one blockhash, which stays valid only briefly, so a user who takes too long to approve can leave a later transaction unsendable. When a transaction fails, expires, or is rejected by the user, withdrawFromYieldVault stops and rejects with a SolanaYieldStepError from @dynamic-labs-sdk/solana. Every transaction before the failed one has already confirmed, so the withdrawal may be partially applied, for example with the shares unstaked from the farm but not yet withdrawn. Read the position with getYieldPosition before you retry. See depositToYieldVault for the error’s properties.

Examples

Withdraw the full position

Supported Chains

withdrawFromYieldVault supports EVM wallet accounts for EVM vaults and Solana wallet accounts for Solana vaults. Pass a wallet account from the same chain family as the vault’s chainName: the API rejects an address from the other family with an HTTP 400 error. Wallet accounts on other chains are not supported, and a wallet provider that does not implement the underlying executeYieldTransaction method throws a WalletProviderMethodUnavailableError.

React

useWithdrawFromYieldVault accepts the same parameters, including onTransactionStepChange. It invalidates useGetYieldPosition on success, so the position refetches automatically. That refetch can still briefly show the old balance, since the withdrawal transaction may not be mined yet (see Waiting for confirmation).
Last modified on October 20, 2026