Skip to main content

Swap Example

A minimal but complete example of executing a token swap on Kroko DEX using ethers.js v6.

Full Code

Key Points

  1. Steps 1 & 2 are one-time per token — you can skip them for subsequent swaps
  2. Native KAS: Use the WKAS address as tokenIn, and skip Steps 1 & 2. The API sets value automatically.
  3. Error handling: Always check for quote.error and swapData.error before proceeding
  4. Slippage: The on-chain minAmountOut / maxAmountIn protection is encoded in the calldata