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:

  1. GET /aggregator/quote β†’ receive quoteId + pricing

  2. GET /aggregator/transaction β†’ receive transaction payload

  3. Sign 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 calldata

Supported 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

Parameter
Type
Description

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

Parameter
Type
Description

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 quoteId is invalid. Fetch a new quote.

  • Single-use. Each quoteId can only be used once with /aggregator/transaction. If consumed or expired, fetch a new quote.

  • ERC-20 approval required before executing. The spender is targetAddress from the quote response.


Step 2 β€” Get Transaction Payload

GET /aggregator/transaction

Required Parameters

Parameter
Type
Description

quoteId

string

The id value returned from Step 1

Optional Parameters

Parameter
Type
Default
Description

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 gasPrice instead of maxFeePerGas/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.data as calldata to the router (targetAddress)

  • Forward the correct msg.value for native token swaps

Last updated