Skip to main content
Prepare transaction data for submitting a withdrawal order through the unified withdrawal wrapper. prepareWithdrawal() is the recommended execution helper for most integrations.
prepareWithdrawal() does not check or enforce allowance. Run prepareWithdrawalAuthorization first if you need approval routing.

Import

import { prepareWithdrawal } from '@paxoslabs/amplify-sdk'

Usage

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

ParameterTypeRequiredDescription
vaultNamestringYesAccount name from AmplifyVault.name (e.g. from getVaultsByConfig())
wantAssetAddressYesToken address user wants to receive
withdrawAmountstringYesAccount shares to withdraw (decimal string)
userAddressAddressYesUser wallet address
chainIdnumberYesChain ID

Return Type

Returns PrepareWithdrawalResult (WithdrawOrderTxData | AtomicWithdrawOrderTxData), ready for writeContract. The SDK automatically selects the standard or atomic variant based on the account’s atomicWithdrawal configuration.
1

Discover account

const [vault] = await getVaultsByConfig({
  yieldType: "CORE",
  chainId: 1,
});
2

Check Authorization

const auth = await prepareWithdrawalAuthorization({
  vaultName: vault.name,
  wantAsset: USDC_ADDRESS,
  withdrawAmount: "1.0",
  userAddress,
  chainId: 1,
});

if (isWithdrawApprovalAuth(auth)) {
  const approvalHash = await walletClient.writeContract(auth.txData);
  await publicClient.waitForTransactionReceipt({ hash: approvalHash });
}
3

Prepare Withdrawal Tx

const withdrawTx = await prepareWithdrawal({
  vaultName: vault.name,
  wantAsset: USDC_ADDRESS,
  withdrawAmount: "1.0",
  userAddress,
  chainId: 1,
});
4

Submit Transaction

await walletClient.writeContract(withdrawTx);