Build Route (Auto)
Build optimal swap routes automatically using KyberSwap's aggregator
The Build Route endpoint is the primary API for obtaining optimal token swap routes. It queries KyberSwap's aggregator, filters results to supported DEX adapters, and returns ready-to-execute transaction data.
Endpoint
POST /api/v1/route/buildRequest
Headers
Content-Type: application/jsonBody Parameters
chain
string
✅
Chain identifier (bsc, ethereum)
tokenIn
string
✅
Input token contract address
tokenOut
string
✅
Output token contract address
amountIn
string
✅
Input amount in wei
sender
string
✅
Sender wallet address
recipient
string
✅
Recipient wallet address
slippageTolerance
integer
❌
Max slippage in basis points (default: 50)
deadline
integer
❌
Unix timestamp deadline (default: 20 min from now)
includedSources
array
❌
DEX sources to include (default: all supported)
gasPrice
string
❌
Custom gas price in wei
Request Example
Supported DEX Sources
uniswap
UniswapV2
V2
uniswapv3
UniswapV3
V3, V4
pancake
PancakeSwap
V2
pancake-v3
PancakeSwap
V3
Response
Success Response (200 OK)
Response Fields
tokenIn
string
Input token address
tokenOut
string
Output token address
amountIn
string
Input amount in wei
amountOut
string
Expected output amount in wei
minAmountOut
string
Minimum output after slippage
gas
string
Estimated gas units
gasPrice
string
Gas price in wei
gasUsd
number
Estimated gas cost in USD
amountInUsd
number
Input value in USD
amountOutUsd
number
Output value in USD
aggregatorAddress
string
DexAggregator contract address
executorAddress
string
Executor contract address
executorData
string
ABI-encoded calldata for execution
value
string
Native token value to send (for ETH/BNB swaps)
swapType
string
Type: simple, batch, multihop, or parallel_multihop
routeInfo
object
Detailed route breakdown
Swap Types
The API automatically detects the optimal swap type:
simple: Single DEX, direct token swap
batch: Multiple DEXes splitting liquidity
multihop: Sequential swaps through intermediate tokens
parallel_multihop: Complex parallel routing
See Swap Types for detailed explanations.
Error Responses
400 Bad Request
500 Internal Server Error
See Error Codes for complete list.
Usage Examples
cURL
JavaScript (fetch)
Python (requests)
Go
Execution Flow
Request Route - Send swap parameters to
/api/v1/route/buildReceive Data - Get
executorDataand contract addressesApprove Token - Call
approve()on input token (if not native)Execute Swap - Call
smartSwapByOrderId()on aggregator contractVerify Output - Check received amount ≥
minAmountOut
See Integration Guide for complete implementation examples.
Best Practices
Recommendations
Always set deadline - Prevent stale transactions
Validate addresses - Check token and wallet addresses before sending
Handle errors gracefully - Implement retry logic for network failures
Check minAmountOut - Verify slippage protection before execution
Monitor gas prices - Adjust based on network conditions
Important Notes
Routes are valid for ~30 seconds due to market volatility
Always approve tokens before swapping (except native tokens)
The
executorDatais ready-to-use ABI-encoded calldataNative token swaps (ETH/BNB) require sending
valuewith transaction
Related Endpoints
Custom Route - Build routes manually
Get Contracts - Get contract addresses
Get Chains - List supported chains
Need Help?
📖 See Swap Types to understand routing logic
💻 Check JavaScript Integration for full examples
🐛 Report issues on GitHub
Last updated