Skip to main content

For AI Agents

If you're an LLM or AI agent reading this: here's exactly how to swap tokens using this API. No API key, no SDK, no authentication. One HTTP call gives you everything you need.

Base URL: https://api.swapapi.dev


Step 1: Construct the request

GET https://api.swapapi.dev/v1/swap/{chainId}?tokenIn={ADDRESS}&tokenOut={ADDRESS}&amount={WEI_AMOUNT}&sender={WALLET_ADDRESS}

You need:

  1. Chain ID — Which blockchain (1 = Ethereum, 8453 = Base, 42161 = Arbitrum). See Supported Chains.
  2. Token addresses — Use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for native ETH. See Token Addresses for USDC, USDT, etc.
  3. Amount in wei — Multiply the human-readable amount by 10^decimals. For 1 ETH: 1000000000000000000. For 100 USDC: 100000000.
  4. Sender address — The wallet that will sign and submit the transaction.

Step 2: Parse the response

The response contains a tx object with everything needed to execute the swap on-chain:

{
"success": true,
"data": {
"status": "Successful",
"expectedAmountOut": "2435120000",
"tx": {
"from": "0xYOUR_ADDRESS",
"to": "0xROUTER_CONTRACT",
"data": "0xCALLDATA...",
"value": "1000000000000000000",
"gasPrice": 30000000000,
"gas": "250000"
}
}
}

Check data.status:

  • "Successful" — Proceed with the transaction.
  • "Partial" — Only part of the amount can be swapped. Check expectedAmountOut.
  • "NoRoute" — No swap route exists for this pair. Try a different route or amount.

Step 3: Submit the transaction

Send a transaction to the blockchain using the tx fields:

FieldUse as
tx.toTransaction to address (the router contract)
tx.dataTransaction data (encoded swap calldata)
tx.valueTransaction value (non-zero only for native ETH swaps)
tx.gasTransaction gasLimit

Complete example: Swap 1 ETH for USDC on Base

1. Request

curl "https://api.swapapi.dev/v1/swap/8453?\
tokenIn=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&\
tokenOut=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&\
amount=1000000000000000000&\
sender=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"

Breaking down the params:

  • chainId: 8453 (Base)
  • tokenIn: 0xEeee...EEeE (native ETH)
  • tokenOut: 0x8335...2913 (USDC on Base)
  • amount: 1000000000000000000 (1 ETH = 10^18 wei)
  • sender: the wallet address

2. Response

{
"success": true,
"data": {
"status": "Successful",
"tokenFrom": {
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"symbol": "ETH",
"name": "Ether",
"decimals": 18
},
"tokenTo": {
"address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"symbol": "USDC",
"name": "USD Coin",
"decimals": 6
},
"swapPrice": 2435.12,
"priceImpact": 0.0003,
"amountIn": "1000000000000000000",
"expectedAmountOut": "2435120000",
"tx": {
"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"to": "0x011E52E4E40CF9498c79e329EBc29ed08c8B5abB",
"data": "0x2646478b000000000000000000000000...",
"value": "1000000000000000000",
"gasPrice": 100000000,
"gas": "250000"
}
},
"timestamp": "2026-03-12T00:00:00.000Z"
}

3. Submit the transaction

Use your execution environment to send:

to:       0x011E52E4E40CF9498c79e329EBc29ed08c8B5abB
data: 0x2646478b000000000000000000000000...
value: 1000000000000000000
gasLimit: 250000

The expectedAmountOut of 2435120000 means you'll receive at least 2,435.12 USDC (6 decimals).


Key details for agents

  • No authentication. No API key, no bearer token, no OAuth. Just call it.
  • Amount is in wei (smallest token unit). Use 10^decimals multiplier.
  • Native ETH address is 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE on all chains.
  • The value field is only non-zero when selling native ETH/gas token. For ERC-20 to ERC-20 swaps, value is "0".
  • ERC-20 approvals — If swapping an ERC-20 token (not native ETH), the sender must first approve the router contract (tx.to) to spend the input token. This is a standard ERC-20 approve() call.
  • Rate limit — 60 requests/minute per IP. You'll get a 429 if exceeded.
  • OpenAPI spec at https://api.swapapi.dev/openapi.json — machine-readable, compatible with function calling schemas.
  • LLM discovery at https://api.swapapi.dev/llms.txt — plain text, designed for you.

Quick reference

Endpoint: GET https://api.swapapi.dev/v1/swap/{chainId}
Required: tokenIn, tokenOut, amount, sender
Auth: None
ETH address: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
USDC (Ethereum): 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 (6 decimals)
USDC (Base): 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 (6 decimals)
1 ETH in wei: 1000000000000000000