> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# withdrawFromYieldVault

# withdrawFromYieldVault

Withdraws assets from an [Earn](https://docs.dynamic.xyz/docs/earn/overview.md) vault, then signs and sends the transaction for you. As with [`depositToYieldVault`](https://docs.dynamic.xyz/docs/javascript/reference/client/deposit-to-yield-vault), 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

```javascript theme={"system"}
import { withdrawFromYieldVault } from '@dynamic-labs-sdk/client';

const { transactionHash } = await withdrawFromYieldVault({
  vaultId: 'fb-eth-galaxy-usdc-fw-01',
  walletAccount,
  amount: '10.5', // 10.5 USDC — human-readable units, not raw
});

console.log('Transaction hash:', transactionHash);
```

## Parameters

| Parameter | Type | Description |
| - | - | - |
| `vaultId` | `string` | Opaque vault identifier, from [`listYieldVaults`](https://docs.dynamic.xyz/docs/javascript/reference/client/list-yield-vaults). |
| `walletAccount` | `WalletAccount` | The wallet account whose position is being withdrawn. Must be an EVM wallet account for an EVM vault, or a Solana wallet account for a Solana vault. |
| `amount` | `string` | How much of the vault's underlying asset to withdraw, in the asset's human-readable units (`'10.5'` USDC, not `'10500000'`). Rejected when it carries more precision than the asset supports. |
| `receiverAddress` | `string` (optional) | The address that receives the withdrawn assets. Defaults to `walletAccount`'s own address. Must equal the wallet's own address for a Solana vault. |
| `onTransactionStepChange` | `(progress: YieldTransactionProgress) => void` (optional) | Callback invoked as each transaction of a multi-transaction withdrawal begins, which only happens for Solana vaults. `progress` has `ordinal` (zero-based position), `total` (number of transactions), and an optional `label` such as `'unstake-from-farm'`, `'withdraw'`, or `'post-withdraw'`. |
| `sponsored` | `boolean` (optional) | Whether the transaction is gas-sponsored. When omitted, an EVM withdrawal is sponsored if EVM gas sponsorship is enabled and the wallet is a Dynamic embedded wallet, and a Solana withdrawal is not sponsored. `false` never sponsors. `true` requires sponsorship and rejects when it is unavailable. |
| `client` | `DynamicClient` (optional) | The Dynamic client instance. Only required when using multiple Dynamic clients. |

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

> [!WARNING]
>
> For an EVM vault, a resolved `withdrawFromYieldVault` call means the withdrawal was **sent**, not that it finished. See [Waiting for confirmation](#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:

```typescript theme={"system"}
import { withdrawFromYieldVault, getActiveNetworkData } from '@dynamic-labs-sdk/client';
import { createPublicClientFromNetworkData } from '@dynamic-labs-sdk/evm/viem';

const { transactionHash } = await withdrawFromYieldVault({
  vaultId: 'fb-eth-galaxy-usdc-fw-01',
  walletAccount,
  amount: '10.5',
});

const { networkData } = await getActiveNetworkData({ walletAccount });
const publicClient = createPublicClientFromNetworkData({ networkData });

const receipt = await publicClient.waitForTransactionReceipt({
  hash: transactionHash as `0x${string}`,
});

if (receipt.status !== 'success') {
  throw new Error('Withdrawal transaction reverted');
}
```

### 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`](https://docs.dynamic.xyz/docs/javascript/reference/client/get-yield-position) before you retry. See [`depositToYieldVault`](https://docs.dynamic.xyz/docs/javascript/reference/client/deposit-to-yield-vault#solana-vaults) for the error's properties.

## Examples

### Withdraw the full position

```javascript theme={"system"}
import {
  getYieldDetails,
  getYieldPosition,
  withdrawFromYieldVault,
} from '@dynamic-labs-sdk/client';
import { formatUnits } from 'viem';

async function withdrawAll(vaultId, walletAccount) {
  const [details, position] = await Promise.all([
    getYieldDetails({ vaultId }),
    getYieldPosition({ vaultId, walletAccount }),
  ]);

  const amount = formatUnits(BigInt(position.assets), details.assetDecimals);

  return withdrawFromYieldVault({ vaultId, walletAccount, amount });
}
```

## 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

```tsx theme={"system"}
import { useWithdrawFromYieldVault } from '@dynamic-labs-sdk/react-hooks';

function WithdrawButton({ vaultId, walletAccount, amount, onComplete }) {
  const { mutate: withdraw, isPending } = useWithdrawFromYieldVault();

  return (
    <button
      onClick={() =>
        withdraw(
          { vaultId, walletAccount, amount },
          { onSuccess: ({ transactionHash }) => onComplete(transactionHash) },
        )
      }
      disabled={isPending}
    >
      Withdraw
    </button>
  );
}
```

`useWithdrawFromYieldVault` accepts the same parameters, including `onTransactionStepChange`. It invalidates [`useGetYieldPosition`](https://docs.dynamic.xyz/docs/javascript/reference/client/get-yield-position) 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](#waiting-for-confirmation)).

## Related

* [`depositToYieldVault`](https://docs.dynamic.xyz/docs/javascript/reference/client/deposit-to-yield-vault) - Deposit into a vault
* [`getYieldPosition`](https://docs.dynamic.xyz/docs/javascript/reference/client/get-yield-position) - Read the wallet's remaining position


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.