Skip to main content
This example demonstrates how to withdraw from a DeFi yield strategy using the Pods API with JavaScript/TypeScript. It includes both same-chain withdrawal and cross-chain withdrawal, where withdrawn funds are bridged to a different destination chain.

Overview

This example covers:
  • Checking existing strategy positions
  • Generating withdrawal transaction bytecode
  • Withdrawing to the same chain
  • Withdrawing cross-chain with toChainId and toTokenAddress
  • Executing the returned transactions
  • Tracking cross-chain completion by ID

Prerequisites

  • Node.js 18+
  • Pods API key
  • Wallet with an existing position in the selected strategy
  • RPC URL for the strategy chain
  • Basic understanding of async/await

Installation

Environment Variables

Create a .env file:
Never commit your .env file to version control. Add it to .gitignore.

Step-by-Step Walkthrough

1. Initialize API Client

2. Check Current Positions

3. Generate Same-Chain Withdrawal Bytecode

4. Generate Cross-Chain Withdrawal Bytecode

To withdraw from the strategy chain and bridge the proceeds to another chain, pass toChainId or chainIdOut plus toTokenAddress.
The amount is the amount to withdraw from the source strategy. For cross-chain withdrawals, Pods returns origin-chain transaction bytecode and a quote describing the destination-chain output.

5. Execute Transactions (atomic batch)

Batch all source-chain bytecode legs into one transaction. See Executing Bytecode and EIP-7702.

6. Track Cross-Chain Withdrawal Status

Cross-chain withdrawals complete asynchronously after the origin-chain transactions are confirmed. Use the returned id to track completion.
Same-chain withdrawals do not require polling because the withdrawal completes inline with the user’s signed transaction. You can still call GET /actions/:id with the returned id for record-keeping.

Running the Example

Expected Output

Next Steps

Strategy Deposit

Deposit into yield strategies

Yield Withdrawal Guide

Review all withdrawal parameters and response shapes

Cross-Chain Swap

Execute cross-chain token swaps

API Reference

View complete API documentation