EVM Swap Integration Guide
How to execute same-chain swaps on EVM networks using Fly Trade's APIs
This guide shows how to execute a swap on EVM networks (Ethereum, Polygon, BSC, Arbitrum, etc.) using Fly Trade's API in 3 steps:
Get a quote (pricing + route + constraints)
Fetch transaction payload with the quote ID
Sign and send the transaction to the network
Prerequisites
An EVM RPC connection (Infura, Alchemy, QuickNode, or self-hosted node)
A wallet that can sign EVM transactions (MetaMask, WalletConnect, ethers.js Signer, or backend private key)
Sufficient balance of the tokens you want to swap and their token contract addresses
How the Flow Works
The high-level swap flow is:
Call
/aggregator/quoteto receive aquoteId, estimated output amount, and swap detailsCall
/aggregator/transactionwith thequoteIdto receive the transaction data (to, data, value, gas parameters)Sign the transaction with the user's wallet
Send the signed transaction to the network
Wait for confirmation
Alternative: Instead of calling quote and transaction separately, you can use the /aggregator/quote/transaction endpoint to get both in a single request. Note that this combined endpoint does not provide gas estimation.
Step 1 — Get a Quote
Endpoint:
Method:
GETPath:
/aggregator/quote
Required Parameters:
network
Network name (e.g., ethereum, polygon, bsc, arbitrum, base). See the network dropdown on Swagger for all supported network names
fromTokenAddress
Token contract address to swap from. Use 0x0000000000000000000000000000000000000000 for native token (ETH/MATIC/BNB)
toTokenAddress
Token contract address to swap to. Use 0x0000000000000000000000000000000000000000 for native token
sellAmount
Amount in smallest unit (wei). For 1 ETH write 1000000000000000000
slippage
Allowed slippage (e.g., 0.005 for 0.5%, 0.01 for 1%)
fromAddress
Wallet address initiating the swap
toAddress
Wallet address receiving the swapped tokens
gasless
Set to true for gasless transactions (Fly Trade pays gas), or false for standard transactions
Optional Parameters
Affiliate Fee:
affiliateAddress: Address to receive affiliate feesaffiliateFee: The fee percentage. For example: 1% = 0.01
Affiliate fees are deducted from the fromTokenAddress amount and sent to the specified address.
Example Request:
Example Response:
Save the id as quoteId for Step 2.
Important Quote Constraints:
Quote Expiry: Each quote has a 5-minute expiration window. After 5 minutes, the quoteId becomes invalid and you will not be able to fetch the transaction payload. If your quote has expired, you must request a fresh quote before proceeding.
Single-Use Quotes: Each quote can only be used to fetch the transaction payload once. After successfully calling /aggregator/transaction with a quoteId, that quote is consumed and cannot be reused. If you need to execute another swap or retry, you must fetch a new quote.
Step 2 — Get Transaction Payload
Endpoint:
Method:
GETPath:
/aggregator/transaction
Required Parameters:
quoteId
The quote id returned from Step 1
Optional Parameters:
estimateGas
Whether to estimate gas when building the transaction. If true, ensures token approval and balance checks are performed. If gas estimation fails, returns error "Couldn't estimate gas"
true
Important: When estimateGas=true, you must have:
Sufficient token approval for the router contract (for ERC-20 swaps)
Enough token balance for the swap
Otherwise, the endpoint will return an error and fail to generate the transaction
Example Request:
Example Response:
Alternative: Combined Quote + Transaction Endpoint
For faster integration, you can fetch both quote and transaction data in a single request.
Endpoint:
Method:
GETPath:
/aggregator/quote/transaction
Parameters:
Accepts all parameters from the /aggregator/quote endpoint (network, fromTokenAddress, toTokenAddress, sellAmount, slippage, fromAddress, toAddress, gasless).
Note: fromAddress and toAddress are required for this endpoint and it doesn't estimate gas.
Example Request:
Example Response:
Returns both quote data and transaction payload in one response:
json
Gasless Swaps (Optional)
When gasless=true in the quote request, the user pays for gas in fromToken instead of native tokens, and Fly Trade's relayer executes the transaction on your behalf.
Important Constraints:
Only works for ERC-20 tokens - Native token swaps cannot be gasless
You still need to approve tokens first before executing the swap for the tokens which don't support permit
The gas fee is deducted from the
fromTokenamount
Example Gasless Quote Request:
Example Gasless Quote Response:
json
Executing a Gasless Swap:
After receiving the quote response, you need to:
Sign the message from
typedDatain the quote response with your wallet to generateswapSignature(Optional) Handle token approval:
If the token supports EIP-2612 permit: Sign a permit message to generate
permitSignatureandpermitDeadlineIf the token doesn't support permit: Approve the token for the router address first, then leave
permitSignatureandpermitDeadlineempty
Call the execute swap endpoint with the signatures
Execute Swap Endpoint:
Method:
POSTPath:
/user-manager/execute-swap
Required Parameters:
networkName
Network name (e.g., sonic, ethereum, polygon)
Yes
quoteId
The quote id returned from the quote endpoint
Yes
swapSignature
Signature of the typedData message from the quote response
Yes
permitSignature
EIP-2612 permit signature (only if token supports permit)
Conditional
permitDeadline
Unix timestamp for permit expiration (only if token supports permit)
Conditional
Example Request:
Gasless Swap Flow Example (TypeScript):
typescript
Step 3 — Execute the Swap Transaction
Once you have the transaction payload (from Step 2 or the combined endpoint), you can execute it using your preferred web3 library.
Important: Depending on the blockchain, the transaction response may use EIP-1559 format with maxFeePerGas and maxPriorityFeePerGas (if the chain supports EIP-1559) or legacy format with gasPrice. Make sure your wallet/library supports both transaction types.
Integration Examples
Example 1: Frontend Integration (React + Ethers.js)
Example for integrating swaps in a React frontend application:
Example 2: Smart Contract Integration
If you're building a smart contract that needs to execute swaps, here's how to integrate:
Solidity Contract Example:
Off-chain Script to Call Contract:
Important Notes for Contract Integration:
Set
estimateGas=falsewhen getting transaction data for contract callsThe contract must approve the Fly router before swapping ERC-20 tokens
Pass the transaction data from Fly Trade API directly to the router as calldata
The router address is
0xa6e941eab67569ca4522f70d343714ff51d571c4on Ethereum (check for other chains)
Network Support
Fly Trade supports swaps on multiple EVM networks. You must use the network name (not chain ID) in API requests:
ethereum
Ethereum Mainnet
polygon
Polygon
bsc
BNB Smart Chain
arbitrum
Arbitrum One
optimism
Optimism
base
Base
avalanche
Avalanche C-Chain
blast
Blast
manta
Manta Pacific
scroll
Scroll
fantom
Fantom
polygonzk
Polygon zkEVM
zksync
zkSync Era
linea
Linea
solana
Solana (see separate guide)
For the complete and up-to-date list of supported network names, refer to the network dropdown in our Swagger documentation for aggregator/quote endpoint or get it from /token-manager/networks endpoint.
Last updated