Skip to content

Platform REST API — Swaps

Execute trades against the AMM. Six routes cover exact-input and exact-output in both directions, for token pairs and for native KNYX.

Wallet-level auth on from — these spend funds. See Platform REST API.

Choosing a route

I want toRoute
Spend exactly X tokensexecute_exact_tokens_for_tokens
Receive exactly Y tokensexecute_tokens_for_exact_tokens
Spend exactly X KNYXexecute_exact_knyx_for_tokens
Receive exactly Y tokens, paying KNYXexecute_knyx_for_exact_tokens
Spend exactly X tokens, receive KNYXexecute_exact_tokens_for_knyx
Receive exactly Y KNYXexecute_tokens_for_exact_knyx

Endpoints

POST /api/swap/execute_exact_tokens_for_tokens

InputMeaning
amount_inExact amount to spend
amount_out_minMinimum acceptable output
token1, token2Input and output token addresses
fromSpending wallet; must be authenticated
toReceives the output

POST /api/swap/execute_tokens_for_exact_tokens

InputMeaning
amount_in_maxMaximum willing to spend
amount_outExact amount to receive
token1, token2, from, toAs above

POST /api/swap/execute_exact_knyx_for_tokens

POST /api/swap/execute_knyx_for_exact_tokens

InputMeaning
amount_out_minMinimum acceptable output
tokenOutput token address
from, toAs above

POST /api/swap/execute_exact_tokens_for_knyx

POST /api/swap/execute_tokens_for_exact_knyx

InputMeaning
amount_in_maxMaximum willing to spend
amount_outExact amount to receive
token1, token2, from, toAs above

Slippage

Set the bounds deliberately

amount_out_min and amount_in_max are what protect you from an adverse price move between quoting and execution. Passing 0 or a very large value disables that protection entirely, and a swap can then execute at any price the pool happens to offer.

A common approach is to quote first and allow a tolerance:

js
const [, expected] = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);
const amountOutMin = expected * 995n / 1000n;   // 0.5%

Fees

The AMM charges 0.2% per swap — amountIn × 998 / 1000. This differs from Uniswap V2's 0.3%; see Swapping.

KriptoNyx testnet — chain ID 3009 (kriptonyx_3009-1)