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 a cross-chain swap quote
  • Generating transaction bytecode
  • Executing the swap transaction
  • Monitoring transaction status across chains

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 Cross-Chain Quote

Cross-chain swaps use bridge providers like TeleSwap or Mayan and may take several minutes to complete.

3. Generate Bytecode

4. Execute Origin Transactions (atomic batch)

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

5. Monitor Status

Use the quote ID for quote status. The bytecode response also returns an id; use it with GET /actions/{id} when you need the execution record.

Webhook Alternative

Instead of polling, you can configure webhooks to receive status updates:

Error Handling

Running the Example

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