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 action that is not sponsored, a resolved withdrawFromYieldVault call means the withdrawal transaction mined successfully. A sponsored EVM action resolves after the relayer reports the transaction hash, so it can still fail or revert afterward. See Confirmation and errors before showing a success state to the user.

Confirmation and errors

EVM transaction errors

For an EVM vault action that is not sponsored, the built-in EVM wallet provider waits for the transaction receipt before withdrawFromYieldVault resolves. If the mined transaction reverts, the call rejects with EvmTransactionRevertedError. If another transaction takes its nonce first, the call rejects with EvmTransactionReplacedError. Both errors are exported from @dynamic-labs-sdk/evm. See EVM transaction errors for the error fields and an instanceof example. When the EVM action is sponsored, withdrawFromYieldVault resolves after the relayer reports the transaction hash, and the transaction can still fail or revert afterward. 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 while the position catches up with the confirmed transaction (see Confirmation and errors).
Last modified on November 18, 2026