Skip to main content
This script runs the complete partner flow against the Sandbox: it signs every API request with HMAC-SHA256, requests an indicative and a firm quote, approves the input token, submits commitFirmQuote from your wallet, and confirms settlement with GET /v1/executions. It also defines the signRequest helper used in the other code samples.
The script sends real on-chain transactions from your wallet. Run it against the Sandbox (Kaia Kairos testnet) with test tokens.

What it does

1

Discover corridors

GET /v1/corridors — finds the corridor for SWAP_PAIR and resolves corridor_id, from_token and to_token.
2

Check rates

GET /v1/rates — prints the current mid-market rate for every corridor.
3

Indicative quote

POST /v1/quote — prints the output amount and fee breakdown.
4

Firm quote

POST /v1/firm-quote — returns the signed quote and execution calldata.
5

Approve

Checks the input token’s allowance for the FxEngine contract and approves it if needed.
6

Execute

Sends the transaction to execution.contract with execution.calldata.
7

Verify

Polls GET /v1/executions?quote=… until the swap is indexed as SETTLED.
Approval is one-time per token. The script approves after receiving the firm quote to stay self-contained; in production, approve the FxEngine contract ahead of time so a firm quote never waits on an approval (firm quotes expire after 60 seconds).

Requirements

  • Node.js 18 or later and ethers v6: npm install ethers@6
  • Sandbox API credentials (API key and secret)
  • A wallet registered to your credential with swap permission, on a corridor where accessible is true
  • Enough of the input token in that wallet, and KAIA for gas

Configuration

Set these environment variables: Save the script as ratio-swap.mjs and run:

Script

ratio-swap.mjs

Troubleshooting