Appearance
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 to | Route |
|---|---|
| Spend exactly X tokens | execute_exact_tokens_for_tokens |
| Receive exactly Y tokens | execute_tokens_for_exact_tokens |
| Spend exactly X KNYX | execute_exact_knyx_for_tokens |
| Receive exactly Y tokens, paying KNYX | execute_knyx_for_exact_tokens |
| Spend exactly X tokens, receive KNYX | execute_exact_tokens_for_knyx |
| Receive exactly Y KNYX | execute_tokens_for_exact_knyx |
Endpoints
POST /api/swap/execute_exact_tokens_for_tokens
| Input | Meaning |
|---|---|
amount_in | Exact amount to spend |
amount_out_min | Minimum acceptable output |
token1, token2 | Input and output token addresses |
from | Spending wallet; must be authenticated |
to | Receives the output |
POST /api/swap/execute_tokens_for_exact_tokens
| Input | Meaning |
|---|---|
amount_in_max | Maximum willing to spend |
amount_out | Exact amount to receive |
token1, token2, from, to | As above |
POST /api/swap/execute_exact_knyx_for_tokens
POST /api/swap/execute_knyx_for_exact_tokens
| Input | Meaning |
|---|---|
amount_out_min | Minimum acceptable output |
token | Output token address |
from, to | As above |
POST /api/swap/execute_exact_tokens_for_knyx
POST /api/swap/execute_tokens_for_exact_knyx
| Input | Meaning |
|---|---|
amount_in_max | Maximum willing to spend |
amount_out | Exact amount to receive |
token1, token2, from, to | As 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.