Swap API
Endpoints for obtaining swap quotes and optimal routing through multi-hop paths.
Get Swap Quote
GET /api/swap/quote
Returns a swap quote including the expected output amount, price impact, and gas estimate.
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
tokenIn | string | Input token contract address |
tokenOut | string | Output token contract address |
amountIn | string | Input amount in wei (smallest unit) |
chain_id | integer | Target chain ID |
Response:
{
"success": true,
"data": {
"tokenIn": "0x...",
"tokenOut": "0x...",
"amountIn": "1000000000000000000",
"amountOut": "3245670000",
"amountOutFormatted": "3245.67",
"priceImpact": 0.12,
"minimumReceived": "3213213300",
"route": [
{ "pool": "0x...", "tokenIn": "WETH", "tokenOut": "USDC", "fee": 3000 }
],
"gasEstimate": "185000"
}
}
Response Fields
| Field | Type | Description |
|---|---|---|
amountOut | string | Expected output amount in smallest unit |
amountOutFormatted | string | Human-readable output amount |
priceImpact | float | Price impact as a percentage |
minimumReceived | string | Minimum output after slippage tolerance |
route | array | Ordered list of pool hops in the swap path |
gasEstimate | string | Estimated gas units for the transaction |
Get Optimal Route
GET /api/swap/route
Returns the optimal multi-hop route for a swap. This endpoint evaluates all possible paths (direct and multi-hop) and returns the one that yields the best output.
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
tokenIn | string | Input token contract address |
tokenOut | string | Output token contract address |
amountIn | string | Input amount in wei |
chain_id | integer | Target chain ID |
Response:
{
"success": true,
"data": {
"route": [
{
"pool": "0xabc...",
"tokenIn": "0x111...",
"tokenOut": "0x222...",
"fee": 3000,
"amountIn": "1000000000000000000",
"amountOut": "500000000000000000000"
},
{
"pool": "0xdef...",
"tokenIn": "0x222...",
"tokenOut": "0x333...",
"fee": 500,
"amountIn": "500000000000000000000",
"amountOut": "3245670000"
}
],
"totalAmountOut": "3245670000",
"totalPriceImpact": 0.15,
"totalGasEstimate": "320000"
}
}
Notes
- The router splits through intermediate tokens (e.g., WETH, USDC) to find paths with lower price impact.
- Multi-hop routes may use up to 3 hops.
- Gas estimates include all hops in the route.
- Slippage tolerance is applied client-side when constructing the transaction.