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
| 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) |
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
Type Definition
Example Response
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;
}
{
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
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;
}
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
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);
}
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);
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 |
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);
}
}