Skip to main content
Prepare transaction data for submitting a withdrawal order to the WithdrawQueue contract.
This function replaces the legacy prepareWithdrawTxData() (also known as prepareWithdrawTransactionData()) from SDK versions prior to 0.4.0. 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 for full migration details.
prepareWithdrawOrderTxData() is a low-level transaction builder and does not perform allowance pre-checks. Use prepareWithdrawalAuthorization when you need approval routing.

Import

import { prepareWithdrawOrderTxData } from "@paxoslabs/amplify-sdk";

Usage

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

ParameterTypeRequiredDescription
yieldTypeYieldTypeYesYield strategy (CORE, TREASURY, FRONTIER)
wantAssetAddressYesToken address you want to receive
userAddressAddressYesUser’s wallet address
chainIdChainIdYesChain ID
amountOfferstringYesVault shares to withdraw (decimal string)
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

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;
}

Examples

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;
}

Withdrawal Flow

1

Authorize Withdrawal

Check and handle vault share approval:
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:
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

ErrorDescriptionResolution
Vault chain mismatchVault not on requested chainVerify chainId matches vault deployment
WithdrawQueue contract address not configuredMissing contract configCheck vault exists for yieldType/chain
BoringVault contract address not configuredMissing vault configCheck vault configuration
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);
  }
}