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

# prepareWithdrawal

> Prepare withdrawal transaction data via the unified withdrawal wrapper

Prepare transaction data for submitting a withdrawal order through the unified withdrawal wrapper.

`prepareWithdrawal()` is the recommended execution helper for most integrations.

<Warning>
  `prepareWithdrawal()` does not check or enforce allowance. Run
  [prepareWithdrawalAuthorization](/v0.5.2/intro/products/earn/developers/api/prepareWithdrawalAuthorization)
  first if you need approval routing.
</Warning>

## Import

```typescript theme={null}
import { prepareWithdrawal } from '@paxoslabs/amplify-sdk'
```

## Usage

```typescript theme={null}
// First discover the vault
const [vault] = await getVaultsByConfig({
  yieldType: 'CORE',
  chainId: 1,
})

const txData = await prepareWithdrawal({
  vaultName: vault.name,
  wantAsset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
  withdrawAmount: '1.0', // Vault shares to offer
  userAddress: '0x1234...',
  chainId: 1,
})

const hash = await walletClient.writeContract(txData)
```

## Parameters

| Parameter        | Type      | Required | Description                                                             |
| ---------------- | --------- | -------- | ----------------------------------------------------------------------- |
| `vaultName`      | `string`  | Yes      | Account name from `AmplifyVault.name` (e.g. from `getVaultsByConfig()`) |
| `wantAsset`      | `Address` | Yes      | Token address user wants to receive                                     |
| `withdrawAmount` | `string`  | Yes      | Account shares to withdraw (decimal string)                             |
| `userAddress`    | `Address` | Yes      | User wallet address                                                     |
| `chainId`        | `number`  | Yes      | Chain ID                                                                |

## Return Type

Returns `PrepareWithdrawalResult` (alias of `WithdrawOrderTxData`), ready for `writeContract`.

## Recommended Flow

<Steps>
  <Step title="Discover account">
    ```typescript theme={null}
    const [vault] = await getVaultsByConfig({
      yieldType: "CORE",
      chainId: 1,
    });
    ```
  </Step>

  <Step title="Check Authorization">
    ```typescript theme={null}
    const auth = await prepareWithdrawalAuthorization({
      vaultName: vault.name,
      wantAsset: USDC_ADDRESS,
      withdrawAmount: "1.0",
      userAddress,
      chainId: 1,
    });

    if (isWithdrawApprovalAuth(auth)) {
      await walletClient.writeContract(auth.txData);
    }
    ```
  </Step>

  <Step title="Prepare Withdrawal Tx">
    ```typescript theme={null}
    const withdrawTx = await prepareWithdrawal({
      vaultName: vault.name,
      wantAsset: USDC_ADDRESS,
      withdrawAmount: "1.0",
      userAddress,
      chainId: 1,
    });
    ```
  </Step>

  <Step title="Submit Transaction">
    ```typescript theme={null}
    await walletClient.writeContract(withdrawTx);
    ```
  </Step>
</Steps>

## Related

* [getVaultsByConfig](/v0.5.2/intro/products/earn/developers/api/getVaultsByConfig) - Discover account names
* [prepareWithdrawalAuthorization](/v0.5.2/intro/products/earn/developers/api/prepareWithdrawalAuthorization) - Authorization routing
* [prepareWithdrawOrderTxData](/v0.5.2/intro/products/earn/developers/api/prepareWithdrawOrderTxData) - Low-level withdraw order builder
* [prepareApproveWithdrawOrderTxData](/v0.5.2/intro/products/earn/developers/api/prepareApproveWithdrawOrderTxData) - Manual account share approval
