Swap API
Generates ready-to-use transaction calldata for executing a swap via the Universal Router. The response can be sent directly as a transaction.POST /api/v1/swap
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
tokenIn | string | Yes | Input token address |
tokenOut | string | Yes | Output token address |
amountIn | string | Conditional | Input amount (required when tradeType=0) |
amountOut | string | Conditional | Output amount (required when tradeType=1) |
tradeType | number | No | 0 = Exact Input (default), 1 = Exact Output |
slippage | number | No | Slippage tolerance as percentage (default: 0.5) |
recipient | string | Yes | Address to receive output tokens |
deadline | number | No | Seconds until expiration (default: 1200 = 20 min) |
Response
| Field | Description |
|---|---|
to | Universal Router address — use as transaction to |
data | Encoded calldata — use as transaction data |
value | Native KAS amount — use as transaction value (non-zero when input is KAS) |
gasEstimate | Estimated gas units |
quote.minAmountOut | Minimum output (Exact Input) — on-chain slippage protection |
quote.maxAmountIn | Maximum input (Exact Output) — on-chain slippage protection |
permit2 | Permit2 contract address |
Slippage Protection
| Trade Type | Field | Formula |
|---|---|---|
| Exact Input (0) | minAmountOut | amountOut × (1 - slippage / 100) |
| Exact Output (1) | maxAmountIn | amountIn × (1 + slippage / 100) |