Skip to content
KernelFlowDevelopers v1
Make your first quote
Swap & Bridge/Start building
KERNELFLOW / DEVELOPERS

Make your first quote

Connect from your backend, request a quote, then integrate signing and tracking.

1. Prepare your backend

Request an API key from dev@kernelflow.org. Configure AGGREGATOR_API_KEY in your server environment or secret manager, and set USER_ADDRESS to the wallet that will sign and pay. The examples use BNB mainnet token addresses; replace amounts and addresses for your trade.

Discover enabled chains
curl --silent --show-error https://api.kernelflow.org/v1/chains

2. Request a quote

This example requests a same-chain BNB quote from USDT to USDC. The amount is 1 USDT expressed as an integer in the input token’s 18-decimal smallest unit. Decimal counts are token-specific; do not assume all stablecoins use the same decimals.

cURL · quote only
curl --get 'https://api.kernelflow.org/v1/quote' \
  --header "X-API-Key: $AGGREGATOR_API_KEY" \
  --data-urlencode 'fromChain=BNB' \
  --data-urlencode 'toChain=BNB' \
  --data-urlencode 'fromToken=0x55d398326f99059fF775485246999027B3197955' \
  --data-urlencode 'toToken=0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d' \
  --data-urlencode 'amount=1000000000000000000' \
  --data-urlencode "fromAddress=$USER_ADDRESS"
TypeScript · Node.js backend
const apiKey = process.env.AGGREGATOR_API_KEY;
const address = process.env.USER_ADDRESS;
if (!apiKey || !address) throw new Error("Set API key and wallet address");

const params = new URLSearchParams({
  fromChain: "BNB", toChain: "BNB",
  fromToken: "0x55d398326f99059fF775485246999027B3197955",
  toToken: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
  amount: "1000000000000000000", fromAddress: address,
});
const response = await fetch(
  "https://api.kernelflow.org/v1/quote?" + params,
  { headers: { "X-API-Key": apiKey }, signal: AbortSignal.timeout(15000) },
);
const result = await response.json();
if (!response.ok) {
  // Retry quotes only on 429/503, with the bounded policy in Errors.
  throw new Error(
    "HTTP " + response.status + ": " + result.msg +
    " (request " + response.headers.get("X-Request-ID") + ")",
  );
}
if (result.code !== 0) throw new Error(result.msg);
const quote = result.data;
// Keep amounts as strings. Display using the output token's decimals.
console.log(quote.toAmount, quote.minToAmount);

3. Approve, sign, and submit

  1. If approval is present, read allowance on approval.token for approval.spender. Obtain sufficient approval and wait for it to be mined.
  2. Use the returned tx.to, tx.data, and tx.value unchanged. On EVM, add the correct chain ID, current nonce, and gas pricing. Use tx.gasLimit when provided.
  3. If the quote expired or the approval took too long, fetch a fresh quote before signing. Without expiresAt, treat quotes as valid for no more than about 60 seconds.
  4. Submit the signed transaction and its matching hash with check: true. Save the returned orderId in your own order record.

4. Track the result

Poll every 3–5 seconds for same-chain trades or 10–15 seconds for cross-chain trades. Stop automatic polling on Succeeded, Failed, Refunded, or WaitVerify. Route WaitVerify to manual review; it is not proof of success or failure.