Overview
This example covers:- Getting an executable quote in one call (
GET /v2/swap/quotewith wallet addresses) - Executing the swap as one atomic EIP-7702 batch
- Handling approvals
Prerequisites
- Node.js 18+
- Pods API key
- Ethereum wallet with tokens to swap
- Basic understanding of async/await
Choose Your Library
- ethers.js
- viem
Using ethers.js v6 for blockchain interactions - the most popular Ethereum library.
Installation
- ethers.js
- viem
Environment Variables
Create a.env file:
Step-by-Step Walkthrough
1. Initialize API Client
2. Get an Executable Quote (one call)
PassoriginAddress and destinationAddress on the quote so the response already includes
executable transactionData. New integrations should not call the legacy
POST /v2/swap/bytecode.
3. Execute Transactions (atomic batch)
output=userOperation on the quote (GET /v2/swap/quote) instead.
Error Handling
Running the Example
Download both files into the same folder to run this example:
same-chain-swap.js and the shared EIP-7702 batch
helper eip7702-batch.js that it imports.Expected Output
Next Steps
Cross-Chain Swap
Execute cross-chain token swaps
Strategy Deposit
Deposit into yield strategies
Swap Guide
Learn more about swaps
API Reference
View complete API documentation