For Agents
AI Agent integration
Fly Trade EVM Swap API — Agent Reference
Overview
Base URL: https://api.fly.trade
Execute a token swap on EVM networks in 3 steps:
GET
/aggregator/quote→ receivequoteId+ pricingGET
/aggregator/transaction→ receive transaction payloadSign and submit transaction to the network
Shortcut: Use GET /aggregator/quote/transaction to get both quote and transaction in one call (no gas estimation).
Decision Tree for Agent Use
Want to swap tokens?
│
├─ Standard swap (user pays gas in native token)
│ ├─ Need gas estimate? → Step 1 (quote) + Step 2 (transaction, estimateGas=true) + Step 3
│ └─ No gas estimate needed? → Combined /quote/transaction + Step 3
│
└─ Calling from a smart contract?
└─ GET /quote/transaction (estimateGas=false, fromAddress=CONTRACT) → forward data as calldataSupported Networks
Use the network string (not chain ID) in all requests.
network value
Chain
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
sonic
Sonic
megaeth
MegaETH
fogo
Fogo
stable
Stable
plasma
Plasma
monad
Monad
hyperevm
HyperEVM
eclipse
Eclipse
unichain
Unichain
berachain
Berachain
abstract
Abstract
ink
Ink
taiko
Taiko
metis
Metis
solana
Solana
morph
Morph
zerogravity
0g
katana
Katana
tempo
Tempo
telos
Telos
pharos
Pharos
Full list: GET /token-manager/networks or check Swagger at https://api.fly.trade/swagger.
These 5 endpoints cover most agent use cases:
Step 1 — Get Quote
GET /aggregator/quote
Fetches a quote estimating the output amount you'll receive for swapping a given input asset. Use this to preview the exchange rate, fees, and expected output before committing to a transaction.
Required Parameters
network
string
Network name (e.g. ethereum)
fromTokenAddress
string
The token address of the token to sell. Use 0x0000000000000000000000000000000000000000 for native token (ETH/MATIC/BNB)
toTokenAddress
string
Token to buy. Use 0x0000000000000000000000000000000000000000 for native token (ETH/MATIC/BNB)
sellAmount
string
The amount of the token to sell.
slippage
number
Max slippage. 0.005 = 0.5%, 0.01 = 1%
fromAddress
string
Wallet address sending the swap
toAddress
string
Wallet address receiving tokens
gasless
boolean
Always set gasless: false. This ensures the user pays gas in the native token. Gasless transactions are deprecated and will be removed in a future release.
Optional Parameters
affiliateAddress
string
Address to receive affiliate fee
affiliateFee
number
Fee percentage. 0.01 = 1%. Deducted from fromToken
Example Request
Response Schema (Standard Swap)
Critical Constraints
Quote expires in 5 minutes. After expiry, the
quoteIdis invalid. Fetch a new quote.Single-use. Each
quoteIdcan only be used once with/aggregator/transaction. If consumed or expired, fetch a new quote.ERC-20 approval required before executing. The spender is
targetAddressfrom the quote response.
Step 2 — Get Transaction Payload
GET /aggregator/transaction
Required Parameters
quoteId
string
The id value returned from Step 1
Optional Parameters
estimateGas
boolean
true
When true, validates token approval and balance before returning. Fails with "Couldn't estimate gas" if checks fail. Set to false for contract integrations.
Example Request
Response Schema
Note: Some chains return legacy format with
gasPriceinstead ofmaxFeePerGas/maxPriorityFeePerGas. Ensure your signer/library handles both.
Alternative: Combined Quote + Transaction (Single Request)
GET /aggregator/quote/transaction
Accepts all parameters from /aggregator/quote. fromAddress and toAddress are required. Gas is not estimated.
Example Request
Response Schema
Step 3 — Execute the Transaction
Submit the transaction object from Step 2 directly to the network using any EVM-compatible library.
TypeScript (ethers.js):
ERC-20 Token Approval
Before swapping an ERC-20 token, the fromAddress must approve the router contract (targetAddress from the quote) to spend the token.
Smart Contract Integration
When calling from a contract, always set estimateGas=false or use the combined /aggregator/quote/transaction endpoint with fromAddress set to your contract address.
Contract requirements:
Approve the Fly router for ERC-20 tokens before calling
Forward
transaction.dataas calldata to the router (targetAddress)Forward the correct
msg.valuefor native token swaps
Last updated