Skip to main content
Redeem vault shares in a single transaction using prepareWithdrawTxData and viem’s wallet client. This script fetches the target vault, prepares the calldata with a slippage safeguard, submits the transaction, and waits for confirmation.

Overview

  • Discover a vault that supports withdrawals.
  • Prepare withdrawal calldata with slippage tolerance.
  • Submit and confirm the transaction with viem.
  • Handle failures by surfacing the APIError payload.

Prerequisites

  • Node.js >= 20
  • viem >= 2.0.0
  • @paxoslabs/amplify-sdk installed and initialized (initAmplifySDK elsewhere in your app)
  • RPC URL (Alchemy, Infura, etc.)
  • Private key with gas and vault shares to redeem
Never commit private keys. Use environment variables or a secrets manager in production.

Complete Code Example

prepareWithdrawTxData throws APIError when a vault, token, or chain is unsupported. Log the endpoint and cause fields to help users fall back to alternative flows when liquidity is unavailable.