/swap
Overview
Unlike most DEX aggregators, our swap endpoint provides graph-based routing plans with optional on-demand calldata generation. Each routing plan specifies the exact amounts and tokens to trade with various liquidity sources, including AMMs and market maker liquidity.
When calldata is not requested, clients can use an encoder to convert the routing plans into transaction calldata for any compatible router contract. This flexibility allows you to choose the most suitable router for your specific use case.
By establishing a standardized format for routing plans, our approach decouples the aggregator API from specific router contracts. This standardization enables seamless encoding and settlement of routing results from any compatible aggregator using any supported router contract.
API schema
Swap endpoint
https://app.swap-net.xyz/api/v1.0/swap
Parameters
sellToken
Yes
Address of sell token¹
Blockchain addresses
buyToken
Yes
Address of buy token¹
Blockchain addresses
sellAmount
Yes²
Amount of sellToken to sell (in base units)
Positive integers
buyAmount
Yes²
Amount of buyToken to buy (in base units)
Positive integers
useRfq
No (default: false
)
Whether to use market maker RFQ liquidity
boolean
includeCalldata
No (default: false
)
Whether to include calldata in the response
boolean
userAddress
Yes if includeCalldata=true
User’s wallet address
Blockchain addresses
slippageTolerance
Yes if includeCalldata=true
Slippage tolerance (0.01
= 1%)
Decimal numbers between 0 and 1
apiKey
Yes
Your API key
string
¹ For native tokens, use either 0x0000000000000000000000000000000000000000
or 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
as the token address.
² Exactly one of sellAmount
or buyAmount
must be provided, but not both. Specify sellAmount
for exact-input swaps or buyAmount
for exact-output swaps.
Simple query example
curl "https://app.swap-net.xyz/api/v1.0/swap\
?chainId=1\
&sellToken=0x853d955acef822db058eb8505911ed77f175b99e\
&buyToken=0x1f9840a85d5af5bf1d1762f925bdaddc4201f984\
&sellAmount=10000000000000000000000\
&apiKey=<Your API Key>"
Response includes:
tokens
Metadata of a list of tokens involved in the routing result. Including token's address
, name
, symbol
, decimals
, usdPrice
, and a referenceId
used to refer to the token.
sell
Contains referenceId
and amount
of the token the user wants to sell, and may include a wrapFromNative
boolean field if the sell token is native token.
buy
Contains referenceId
and amount
of the token the user wants to buy, and may include an unwrapToNative
boolean field if the buy token is native token.
nativeTokenUsdPrice
Current price of the native token on this chain.
routes
A collection of swaps forming a directed acyclic graph that converts all sell tokens into buy tokens. Note that the order of the routes is not guaranteed.
route.name
Name of the liquidity source used by this route (swap).
route.address
Address of the liquidity pool.
route.fromTokens
Array containing referenceId
and amount
of tokens to swap from.
route.toTokens
Array containing referenceId
and amount
of tokens to swap to.
route.details
Additional information about this route (swap) which is used during encoding.
Example with includeCalldata=true
includeCalldata=true
curl "https://app.swap-net.xyz/api/v1.0/swap\
?chainId=999\
&sellToken=0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb\
&buyToken=0x5555555555555555555555555555555555555555\
&sellAmount=10000000000\
&useRfq=true\
&includeCalldata=true\
&userAddress=0x11b86991c6218b36c1d19d4a2e9eb0ce3606eb49\
&slippageTolerance=0.01\
&router=swapnet-router\
&apiKey=<Your API Key>"
Response includes three more fields:
routerAddress
Address of router contract
calldata
Calldata to settle the trade with the router contract
gasLimit
An estimated upper bound of gas consumption, used to config the TX
Last updated