For the complete documentation index, see llms.txt. This page is also available as Markdown.

Creating a DEX swap

Swap tokens on-chain through a DEX from any wallet — permissionless, with no account, KYC, or activity. Quote the swap, approve if needed, then sign and broadcast the returned transaction yourself.

A DEX swap exchanges one token for another on-chain, routed through a decentralized exchange. It is permissionless: no account, no KYC, and no activity is created. You ask for a quote, and KiiChain Pay returns a ready-to-sign transaction (plus any ERC-20 approval) that you sign and broadcast from your own wallet. Routing is handled for you across chains.

This is different from an FX swap. An FX swap is a custodial, tracked activity (a ticket) that KiiChain Pay settles for you. A DEX swap is a plain on-chain swap you broadcast yourself — there is nothing to track through display_status, only the on-chain transaction.

At a glance

Property
Value

Direction

Crypto → Crypto (cross-chain)

Quote endpoint

POST /market/v1/dex/quote (public)

You act

Sign & broadcast the returned transaction with your own wallet

Account / KYC

None

Activity

None — settles fully on-chain

Tracking

On-chain only (watch the transaction hash)

Prerequisites

  • A wallet on the source chain with the tokens to swap and native gas to pay for the transaction. (Gas sponsorship applies only to Kii Wallets, not to self-custody DEX swaps.)

  • The token identifiers for both sides. Discover DEX-enabled tokens from the public endpoint:

curl "https://backend.pay.kiichain.io/blockchain/v1/chains/tokens/all?mode=dex"

Each ChainToken gives you the chain.chain_id, the token.symbol / token.decimals, whether it's native, and its contract_address (absent for native tokens). Use contract_address as the denom for ERC-20 tokens.

Step 1 — Get a DEX quote

Post the source asset (with amount, in base units) and the destination asset. Include your sender_address so the returned transaction is built for your wallet.

The response describes the route and — crucially — includes an unsigned transaction to broadcast:

Field
Meaning

evm_tx

An RLP-serialized unsigned EIP-1559 transaction (0x hex) — the swap itself, ready for you to sign and broadcast.

estimated_amount_out

Minimum output after slippage, in the destination token's base units.

approval_token / approval_address / approval_amount

The ERC-20 allowance the router needs. Present only when an approval is required (empty for native-token swaps).

txs_required

How many transactions the route needs.

swap_price_impact_percent

Estimated price impact, so you can reject a bad route.

Step 2 — Approve the token (if needed)

If approval_token, approval_address, and approval_amount are present, the DEX router needs an ERC-20 allowance before it can pull your tokens. Send a standard approve(spender, amount) transaction from your wallet, where spender is approval_address and amount is at least approval_amount. Native-token swaps skip this step.

Step 3 — Sign & broadcast the swap

evm_tx is a serialized unsigned transaction. Decode it, sign it with your own wallet, and broadcast it. With viem, parse it and hand the fields to your wallet client:

Prefer to have KiiChain Pay sign it? If you hold a delegated Kii Wallet, you can instead decode evm_tx into its to / value / data / chain_id fields and submit it through POST /blockchain/v1/transactions/execute (authenticated, gas-sponsored). That routes the same swap through your Kii Wallet rather than an external one. Check out the actions you can take with internal wallets.

Step 4 — Confirm on-chain

There is no activity to poll — confirmation is on-chain. Wait for the transaction receipt and check the destination-token balance in your wallet:

Full example

An end-to-end ERC-20 → ERC-20 DEX swap with viem: quote, approve if needed, broadcast, confirm.

Last updated