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

# prepareWithdrawOrderTxData

> Prepare a withdrawal order for the WithdrawQueue contract

Prepare transaction data for submitting a withdrawal order to the WithdrawQueue contract.

> [!NOTE]
>
> This function replaces the legacy `prepareWithdrawTxData()` (also known as `prepareWithdrawTransactionData()`) from SDK versions prior to 0.4.2. If you are migrating, note that the new function uses `amountOffer` instead of `amount`, and no longer accepts `slippage` or `deadline` parameters. See the [Changelog](https://developers.paxoslabs.com/v0.4.2/intro/products/earn/developers/changelog.md) for full migration details.

> [!WARNING]
>
> `prepareWithdrawOrderTxData()` is a low-level transaction builder and does not perform allowance pre-checks. Use [prepareWithdrawalAuthorization](https://developers.paxoslabs.com/v0.4.2/intro/products/earn/developers/api/prepareWithdrawalAuthorization.md) when you need approval routing.

## Import

```typescript theme={null}
import { prepareWithdrawOrderTxData } from "@paxoslabs/amplify-sdk";
```

## Usage

```typescript theme={null}
const txData = await prepareWithdrawOrderTxData({
  yieldType: "CORE",
  wantAsset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
  userAddress: "0x1234...",
  chainId: 1,
  amountOffer: "1.0", // Vault shares to offer
});

// Execute withdrawal order
const hash = await walletClient.writeContract(txData);
```

***

## Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `yieldType` | `YieldType` | Yes | Yield strategy (CORE, TREASURY, FRONTIER) |
| `wantAsset` | `Address` | Yes | Token address you want to receive |
| `userAddress` | `Address` | Yes | User's wallet address |
| `chainId` | `ChainId` | Yes | Chain ID |
| `amountOffer` | `string` | Yes | Vault shares to withdraw (decimal string) |

> [!NOTE]
>
> Unlike the old Teller-based withdrawal, the WithdrawQueue does not require `slippage` or `deadline` parameters. Orders are processed by the protocol at the current exchange rate.

***

## Return Type

> [tab] Type Definition
>
> ```typescript theme={null}
> interface WithdrawOrderTxData {
>   abi: typeof WithdrawQueueAbi;
>   address: `0x${string}`;        // WithdrawQueue contract address
>   functionName: "submitOrder";
>   args: [
>     {
>       amountOffer: bigint;              // Shares to withdraw
>       wantAsset: `0x${string}`;         // Want asset address
>       intendedDepositor: `0x${string}`; // User address
>       receiver: `0x${string}`;          // Receiving address
>       refundReceiver: `0x${string}`;    // Refund address
>       signatureParams: {                // Pre-filled approval params
>         approvalMethod: number;
>         approvalV: number;
>         approvalR: `0x${string}`;
>         approvalS: `0x${string}`;
>         submitWithSignature: boolean;
>         deadline: bigint;
>         eip2612Signature: `0x${string}`;
>       };
>     },
>   ];
>   chainId: number;
> }
> ```

> [tab] Example Response
>
> ```typescript theme={null}
> {
>   abi: [/* WithdrawQueue ABI */],
>   address: "0x1234567890abcdef...", // WithdrawQueue address
>   functionName: "submitOrder",
>   args: [
>     {
>       amountOffer: 1000000000000000000n, // 1 share (18 decimals)
>       wantAsset: "0xA0b86991c...",       // USDC address
>       intendedDepositor: "0xabc...",      // User address
>       receiver: "0xabc...",              // Receiving address
>       refundReceiver: "0xabc...",        // Refund address
>       signatureParams: { /* ... */ },    // Approval params
>     }
>   ],
>   chainId: 1,
> }
> ```

***

## Examples

> [tab] Viem
>
> ```typescript theme={null}
> import {
>   prepareWithdrawalAuthorization,
>   isWithdrawApprovalAuth,
>   prepareWithdrawOrderTxData,
> } from "@paxoslabs/amplify-sdk";
> import { createWalletClient, createPublicClient, http } from "viem";
> import { mainnet } from "viem/chains";
>
> async function withdraw(userAddress: `0x${string}`, amount: string) {
>   const walletClient = createWalletClient({
>     account: userAddress,
>     chain: mainnet,
>     transport: http(),
>   });
>   const publicClient = createPublicClient({
>     chain: mainnet,
>     transport: http(),
>   });
>
>   const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
>
>   // Step 1: Check and handle authorization
>   const auth = await prepareWithdrawalAuthorization({
>     yieldType: "CORE",
>     wantAsset: USDC,
>     withdrawAmount: amount,
>     userAddress,
>     chainId: 1,
>   });
>
>   if (isWithdrawApprovalAuth(auth)) {
>     const approveHash = await walletClient.writeContract(auth.txData);
>     await publicClient.waitForTransactionReceipt({ hash: approveHash });
>     console.log("Approval confirmed");
>   }
>
>   // Step 2: Submit withdrawal order
>   const withdrawTx = await prepareWithdrawOrderTxData({
>     yieldType: "CORE",
>     wantAsset: USDC,
>     userAddress,
>     chainId: 1,
>     amountOffer: amount,
>   });
>
>   const hash = await walletClient.writeContract(withdrawTx);
>   const receipt = await publicClient.waitForTransactionReceipt({ hash });
>
>   console.log("Withdrawal order submitted:", receipt.transactionHash);
>   return hash;
> }
> ```

> [tab] Wagmi
>
> ```tsx theme={null}
> import {
>   prepareWithdrawalAuthorization,
>   isWithdrawApprovalAuth,
>   prepareWithdrawOrderTxData,
> } from "@paxoslabs/amplify-sdk";
> import {
>   useAccount,
>   useWriteContract,
>   useWaitForTransactionReceipt,
>   usePublicClient,
> } from "wagmi";
> import { useState } from "react";
>
> function WithdrawForm() {
>   const { address } = useAccount();
>   const publicClient = usePublicClient();
>   const { writeContractAsync, data: hash } = useWriteContract();
>   const { isLoading: isConfirming } = useWaitForTransactionReceipt({ hash });
>   const [amount, setAmount] = useState("");
>   const [status, setStatus] = useState("idle");
>
>   async function handleWithdraw() {
>     if (!address || !amount) return;
>
>     const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
>
>     try {
>       // Authorize
>       setStatus("Checking approval...");
>       const auth = await prepareWithdrawalAuthorization({
>         yieldType: "CORE",
>         wantAsset: USDC,
>         withdrawAmount: amount,
>         userAddress: address,
>         chainId: 1,
>       });
>
>       if (isWithdrawApprovalAuth(auth)) {
>         setStatus("Approving...");
>         const approveHash = await writeContractAsync(auth.txData);
>         await publicClient.waitForTransactionReceipt({ hash: approveHash });
>       }
>
>       // Submit withdrawal
>       setStatus("Submitting withdrawal...");
>       const withdrawTx = await prepareWithdrawOrderTxData({
>         yieldType: "CORE",
>         wantAsset: USDC,
>         userAddress: address,
>         chainId: 1,
>         amountOffer: amount,
>       });
>
>       await writeContractAsync(withdrawTx);
>       setStatus("Withdrawal order submitted!");
>     } catch (error) {
>       setStatus(`Error: ${(error as Error).message}`);
>     }
>   }
>
>   return (
>     <div>
>       <input
>         type="text"
>         value={amount}
>         onChange={(e) => setAmount(e.target.value)}
>         placeholder="Amount to withdraw"
>       />
>       <button onClick={handleWithdraw} disabled={isConfirming}>
>         {isConfirming ? "Confirming..." : "Withdraw"}
>       </button>
>       <p>{status}</p>
>     </div>
>   );
> }
> ```

***

## Withdrawal Flow

**1. Authorize Withdrawal**

Check and handle vault share approval:

```typescript theme={null}
const auth = await prepareWithdrawalAuthorization({
  yieldType: "CORE",
  wantAsset: USDC_ADDRESS,
  withdrawAmount: "1.0",
  userAddress: "0x...",
  chainId: 1,
});

if (isWithdrawApprovalAuth(auth)) {
  await walletClient.writeContract(auth.txData);
}
```

**2. Submit Withdrawal Order**

Submit the order to the WithdrawQueue:

```typescript theme={null}
const withdrawTx = await prepareWithdrawOrderTxData({
  yieldType: "CORE",
  wantAsset: USDC_ADDRESS,
  userAddress: "0x...",
  chainId: 1,
  amountOffer: "1.0",
});
await walletClient.writeContract(withdrawTx);
```

**3. Wait for Processing**

The WithdrawQueue processes orders. Once processed, funds are sent to your wallet automatically.

***

## Error Handling

| Error | Description | Resolution |
| - | - | - |
| `Vault chain mismatch` | Vault not on requested chain | Verify chainId matches vault deployment |
| `WithdrawQueue contract address not configured` | Missing contract config | Check vault exists for yieldType/chain |
| `BoringVault contract address not configured` | Missing vault config | Check vault configuration |

```typescript theme={null}
import { prepareWithdrawOrderTxData, APIError } from "@paxoslabs/amplify-sdk";

try {
  const txData = await prepareWithdrawOrderTxData({
    yieldType: "CORE",
    wantAsset: USDC_ADDRESS,
    userAddress: "0x...",
    chainId: 1,
    amountOffer: "1.0",
  });
} catch (error) {
  if (error instanceof APIError) {
    console.error("SDK Error:", error.message);
  }
}
```

***

## Related

* [prepareWithdrawal](https://developers.paxoslabs.com/v0.4.2/intro/products/earn/developers/api/prepareWithdrawal.md) - Unified withdrawal wrapper
* [prepareWithdrawalAuthorization](https://developers.paxoslabs.com/v0.4.2/intro/products/earn/developers/api/prepareWithdrawalAuthorization.md) - Unified authorization flow
* [prepareApproveWithdrawOrderTxData](https://developers.paxoslabs.com/v0.4.2/intro/products/earn/developers/api/prepareApproveWithdrawOrderTxData.md) - Approve vault shares
* [Withdrawals Guide](https://developers.paxoslabs.com/v0.4.2/intro/products/earn/developers/guides/withdrawals.md) - Complete withdrawal integration guide
* [Deposits](https://developers.paxoslabs.com/v0.4.2/intro/products/earn/developers/api/deposit-workflow.md) - Deposit into vaults


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