Skip to main content

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:

ParameterTypeDescription
tokenInstringInput token contract address
tokenOutstringOutput token contract address
amountInstringInput amount in wei (smallest unit)
chain_idintegerTarget 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

FieldTypeDescription
amountOutstringExpected output amount in smallest unit
amountOutFormattedstringHuman-readable output amount
priceImpactfloatPrice impact as a percentage
minimumReceivedstringMinimum output after slippage tolerance
routearrayOrdered list of pool hops in the swap path
gasEstimatestringEstimated 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:

ParameterTypeDescription
tokenInstringInput token contract address
tokenOutstringOutput token contract address
amountInstringInput amount in wei
chain_idintegerTarget 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.