Skip to main content
This example demonstrates how to swap tokens across different blockchain networks using the Pods API with JavaScript/TypeScript.

Overview

This example covers:
  • Getting an executable cross-chain quote in one call (GET /v2/swap/quote with wallet addresses)
  • Executing the origin-chain legs as one atomic EIP-7702 batch
  • Monitoring status across chains (quoteId vs the Action id)

Prerequisites

  • Node.js 18+
  • Pods API key
  • Wallet with tokens on the origin chain
  • Basic understanding of async/await

Choose Your Library

Using ethers.js v6 for blockchain interactions - the most popular Ethereum library.

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. Get an Executable Cross-Chain Quote (one call)

Pass originAddress, destinationAddress, and refundAddress so the response already includes executable transactionData for the origin chain. New integrations should not call the legacy POST /v2/swap/bytecode.
quote.quoteId and the top-level id are different identifiers. Use quote.quoteId with GET /v2/swap/status/{quoteId} for quote settlement, and the top-level id with GET /actions/{id} for the on-chain Action execution record. Cross-chain swaps use bridge providers like TeleSwap or Mayan and may take several minutes to complete.

3. Execute Origin Transactions (atomic batch)

All origin-chain legs must go in one atomic transaction. See Executing Bytecode and cross-chain-swap.js.

4. Monitor Status

Poll quote settlement with quote.quoteId. When you need the on-chain Action execution record instead, poll GET /actions/${actionId} with the top-level id from the quote response.

Webhook alternative

Pods can POST ACTION_UPDATE events to your server instead of waiting for the next poll. The body is { messageType, data }, and data matches GET /actions/{id}. Registration and signature verification are in Webhooks. Pass webhookURL on the quote to override the customer default for this swap.

Error Handling

Running the Example

Download both files into the same folder to run this example: cross-chain-swap.js and the shared EIP-7702 batch helper eip7702-batch.js that it imports.

Expected Output

Next Steps

Same-Chain Swap

Execute same-chain token swaps

Strategy Deposit

Deposit into yield strategies

Swap Guide

Learn more about swaps

API Reference

View complete API documentation