Skip to content

Creating a swap ​

Endpoints ​

EndpointPurpose
GET /api/swap/tokensEvery supported token and chain
GET /api/swap/configRuntime configuration, including the fee percent
GET /api/swap/pool-price/bsc-wknyx-usdtCurrent BSC pool spot price
GET /api/swapUsage help for swap creation
POST /api/swapCreate a swap

Create ​

bash
curl -X POST https://bridge.testnet.kriptonyx.com/api/swap \
  -H 'Content-Type: application/json' \
  -d '{
        "source_chain": "BSC",
        "source_token": "USDT",
        "target_chain": "KRIPTONYX",
        "target_token": "KNYX",
        "source_token_amount": 10,
        "target_wallet": "0xYourWallet"
      }'
FieldMeaning
source_chainChain you are sending from
source_tokenAsset you are sending
target_chainChain you want to receive on
target_tokenAsset you want to receive
source_token_amountAmount to send
target_walletWhere the output goes
refund_addressOptional. Where a failed swap returns funds

Chain and token names must match GET /api/swap/tokens exactly.

The response ​

HTTP 201, with the swap as created. This is the response for the worked example at the foot of this page:

json
{
  "swap_id": "d6dc0570-465a-47ff-8f68-c31c7e5f7175",
  "deposit_address": "0x26A59146915ED7E2CB97669Dbc04715593e02D92",
  "source_chain": "KRIPTONYX",
  "source_token": "KNYX",
  "source_amount": "20",
  "target_chain": "KRIPTONYX",
  "target_token": "KUSD",
  "estimated_target_amount": "1.950000",
  "exchange_rate": "0.1",
  "bridge_fee": "0.050000",
  "bridge_fee_percent": 2.5,
  "expires_at": "2026-09-18T18:43:23.535Z",
  "status": "pending_deposit",
  "route_type": "internal_multi_hop",
  "simpleswap_public_id": null
}
FieldMeaning
swap_idIdentifies the swap. Use it for every tracking call
deposit_addressSend the source asset here. Unique to this swap
source_chain, source_token, source_amountWhat you committed to send
target_chain, target_tokenWhat you will receive
estimated_target_amountOutput after the fee, at the quoted rate. An estimate: the rate locks when the deposit is detected
exchange_rateThe quoted rate
bridge_fee, bridge_fee_percentThe fee in target-token units, and as a percentage
expires_atDeposit deadline — 30 minutes after creation
statuspending_deposit on creation
route_typeHow the bridge will route the swap
simpleswap_public_idSet when a SimpleSwap leg is used; otherwise null

Amounts are strings

Every amount except bridge_fee_percent is a decimal string. Parse it with a decimal library rather than Number — see KNYX and denominations.

Three things to get right

  1. Send to the deposit address, not to the bridge's main address.
  2. Send the exact asset on the exact chain the swap expects. A USDT-on-BSC swap will not detect USDT sent on Ethereum.
  3. Send before the window expires. After expiry the swap moves to swap_expired and the address is no longer monitored.

Set a refund address ​

If the swap fails after you have deposited, funds return to refund_address. On chains where the sending address cannot be inferred reliably, this is the only way the bridge knows where to send them. Set it.

After depositing ​

The blockchain monitor polls the deposit address every 20 seconds. Once the deposit is seen, the rate locks and the rest proceeds automatically.

Follow progress by tracking the swap.

A worked example ​

Swap20 KNYX → 1.95 KUSD
Routeinternal_multi_hop
Rate / fee0.10 — fee 0.05 (2.50%)
Deposit address0x26A59146915ED7E2CB97669Dbc04715593e02D92
Payout0xa8137e6ed03ed52f9bebc46c3e195092717e51aa96d8ac73787bd7cf9b614ea0
Block6,179,202
Elapsed82 seconds

Lifecycle: deposit_wallet_created → source_token_deposited → rate_locked → vault_locking → vault_locked → payout_processing → target_token_sent

KriptoNyx testnet — chain ID 3009 (kriptonyx_3009-1)