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/build

Request

Headers

Content-Type: application/json

Body Parameters

Parameter
Type
Required
Description

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

Source
Description
Versions

uniswap

UniswapV2

V2

uniswapv3

UniswapV3

V3, V4

pancake

PancakeSwap

V2

pancake-v3

PancakeSwap

V3

Default Behavior

If includedSources is not specified, all supported DEX adapters will be considered for routing.

Response

Success Response (200 OK)

Response Fields

Field
Type
Description

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

  1. Request Route - Send swap parameters to /api/v1/route/build

  2. Receive Data - Get executorData and contract addresses

  3. Approve Token - Call approve() on input token (if not native)

  4. Execute Swap - Call smartSwapByOrderId() on aggregator contract

  5. Verify Output - Check received amount ≥ minAmountOut

See Integration Guide for complete implementation examples.

Best Practices

Need Help?

Last updated