> For the complete documentation index, see [llms.txt](https://documentation.kodiak.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.kodiak.finance/developers/dex/swap-api-kx.md).

# Swap API (kX)

### Overview

This API allows fetching quotes for token swaps and provides transaction data (`calldata`) for execution if the parameters `slippageTolerance`, `deadline`, and `recipient` are specified. This enables direct interaction with smart contracts.

This API is an aggregator of various providers and selects the best ones.

Currently, the following external providers are supported:

1. [OpenOcean](https://openocean.finance/)
2. [Fly (prev MagPie)](https://www.fly.trade/)
3. [OogaBooga](https://www.oogabooga.io/)
4. [Enso](https://docs.enso.build/home)
5. [Kyberswap](https://kyberswap.com/)
6. Kodiak

### Endpoint

**URL:**\
`https://backend.kodiak.finance/quote`

**Method:**\
`GET`

**Content Type:**\
`application/json`

### Query Parameters

<table><thead><tr><th width="215">Parameter</th><th width="108">Required</th><th>Description</th></tr></thead><tbody><tr><td>tokenInAddress</td><td>✅</td><td>Address of the input token for the swap. For native use token = <code>BERA</code> , <code>ETH</code>, or address(0) <code>0x000000000000000000000000000000000000000000</code></td></tr><tr><td>tokenInChainId</td><td>✅</td><td>Chain ID of the input token.</td></tr><tr><td>tokenOutAddress</td><td>✅</td><td>Address of the output token for the swap. For native use token = <code>BERA</code> , <code>ETH</code>, or address(0) <code>0x000000000000000000000000000000000000000000</code></td></tr><tr><td>tokenOutChainId</td><td>✅</td><td>Chain ID of the output token.</td></tr><tr><td>amount</td><td>✅</td><td>Amount of tokens to swap in human terms</td></tr><tr><td>type</td><td>✅</td><td>Type of swap: <code>exactIn</code> (fixed input amount) or <code>exactOut</code> (fixed output amount). <code>exactOut</code> is not supported by most providers, so this is not a recommended method and may show you poor quotes</td></tr><tr><td>refCode</td><td>❌</td><td>Your referral code (received from the Kodiak team)</td></tr><tr><td>referrerFeeBps</td><td>❌</td><td>Your share of fees.  Each referral code has a maximum threshold. Example: 100 = 1%</td></tr><tr><td>recipient</td><td>❌</td><td>The address of the recipient of the swapped tokens. Required for generating <code>calldata</code></td></tr><tr><td>slippageTolerance</td><td>❌</td><td>Allowed slippage percentage as an integer (e.g., 1 for 1%).</td></tr><tr><td>providers</td><td>❌</td><td><p>Case insensitive list of providers separated by commas.</p><p>Available options:  <code>Kodiak</code> , <code>OpenOcean</code>,<code>Magpie</code>,<code>OogaBooga</code>,<code>Enso,Kyberswap</code></p><p></p><p>For example: <code>kodiak,openocean,oogabooga</code></p></td></tr><tr><td>debug</td><td>❌</td><td>Receive additional information on all underlying providers quoted by setting to <code>true</code></td></tr></tbody></table>

### Example Request

{% code overflow="wrap" %}

```
GET https://backend.kodiak.finance/quote?tokenInAddress=BERA&tokenInChainId=80094&tokenOutAddress=0xFCBD14DC51f0A4d49d5E53C2E0950e0bC26d0Dce&tokenOutChainId=80094&amount=100000000000000000000&type=exactIn&recipient=0x5a1e747482F8773fe52Cca9951E956F456EFd0Bf&slippageTolerance=1
```

{% endcode %}

### Example response

```json
{
  "id": "b5c7416a",
  "amountDecimalsUSD": "225.6878516369463",
  "quoteDecimalsUSD": "225.4646160925649",
  "tokenInPriceUSD": "2.256878516369463",
  "tokenOutPriceUSD": "1",
  "priceImpact": "-0.09891340750609146",
  "methodParameters":
    {
      "calldata": "0xd2644d14000000000000000000000000696969696969696969696969696969696969696900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000056bc75e2d63100000000000000000000000000000fcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c19a91d0924faf6130000000000000000000000005a1e747482f8773fe52cca9951e956f456efd0bf000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000c38f339c60126deb3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e301e48f77963d3f7dbd2a4796962bd7f3867fb4000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003245ae401dc0000000000000000000000000000000000000000000000000000000068823556000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e404e45aaf0000000000000000000000006969696969696969696969696969696969696969000000000000000000000000fcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce0000000000000000000000000000000000000000000000000000000000000bb800000000000000000000000043dac637c4383f91b4368041e7a8687da3806cae00000000000000000000000000000000000000000000000340aad21b3b70000000000000000000000000000000000000000000000000000742bd178e640a419f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000043dac637c4383f91b4368041e7a8687da3806cae0000000000000000000000000000000000000000000000022b1c8c1227a00000000000000000000000000000000000000000000000000004d73b54569a90d2a100000000000000000000000000000000000000000000000000000000000000426969696969696969696969696969696969696969000bb8549943e04f40284185054145c6e4e9568c1d3241000064fcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "value": "0x56bc75e2d63100000",
      "to": "0x43Dac637c4383f91B4368041E7A8687da3806Cae",
      "decodedArgs":
        [
          {
            "token": "0x6969696969696969696969696969696969696969",
            "wrap": true,
            "amount": "100000000000000000000",
          },
          {
            "token": "0xFCBD14DC51f0A4d49d5E53C2E0950e0bC26d0Dce",
            "unwrap": false,
            "minAmountOut": "223209969931639256595",
            "receiver": "0x5a1e747482F8773fe52Cca9951E956F456EFd0Bf",
          },
          {
            "router": "0xe301E48F77963D3F7DbD2a4796962Bd7f3867Fb4",
            "data": "0x5ae401dc0000000000000000000000000000000000000000000000000000000068823556000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e404e45aaf0000000000000000000000006969696969696969696969696969696969696969000000000000000000000000fcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce0000000000000000000000000000000000000000000000000000000000000bb800000000000000000000000043dac637c4383f91b4368041e7a8687da3806cae00000000000000000000000000000000000000000000000340aad21b3b70000000000000000000000000000000000000000000000000000742bd178e640a419f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000043dac637c4383f91b4368041e7a8687da3806cae0000000000000000000000000000000000000000000000022b1c8c1227a00000000000000000000000000000000000000000000000000004d73b54569a90d2a100000000000000000000000000000000000000000000000000000000000000426969696969696969696969696969696969696969000bb8549943e04f40284185054145c6e4e9568c1d3241000064fcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
          },
          {
            "feeQuote": "225464616092564905651",
            "surplusFeeBps": "0",
            "refCode": "0",
            "referrerFeeBps": "0",
          },
        ],
    },
  "blockNumber": "8160103",
  "amount": "100000000000000000000",
  "amountDecimals": "100",
  "quote": "225464616092564905651",
  "quoteDecimals": "225.464616092564905651",
  "gasUseEstimate": "306000",
  "gasUseEstimateUSD": "6.920697896398132e-13",
  "gasPriceWei": "501981",
  "route":
    [
      [
        {
          "type": "v3-pool",
          "address": "0x1127f801Cb3ab7BDF8923272949AA7Dba94B5805",
          "tokenIn":
            {
              "chainId": 80094,
              "decimals": "18",
              "address": "0x6969696969696969696969696969696969696969",
              "symbol": "WBERA",
            },
          "tokenOut":
            {
              "chainId": 80094,
              "decimals": "18",
              "address": "0xFCBD14DC51f0A4d49d5E53C2E0950e0bC26d0Dce",
              "symbol": "HONEY",
            },
          "fee": "3000",
          "liquidity": "4493725237081532474168574",
          "sqrtRatioX96": "119153151978651141127607820981",
          "tickCurrent": "8161",
          "amountIn": "60000000000000000000",
          "amountOut": "135275596737333603789",
        },
      ],
      [
        {
          "type": "v3-pool",
          "address": "0x4866Dd95a3bC4eb40Dd1B659489e3410dAe3287f",
          "tokenIn":
            {
              "chainId": 80094,
              "decimals": "18",
              "address": "0x6969696969696969696969696969696969696969",
              "symbol": "WBERA",
            },
          "tokenOut":
            {
              "chainId": 80094,
              "decimals": "6",
              "address": "0x549943e04f40284185054145c6E4e9568C1D3241",
              "symbol": "USDC",
            },
          "fee": "3000",
          "liquidity": "718444640825350202",
          "sqrtRatioX96": "52691600443445573726226992633074205",
          "tickCurrent": "268166",
          "amountIn": "40000000000000000000",
        },
        {
          "type": "v3-pool",
          "address": "0xb16fFD445d3c785476F87017b79423eC9057406b",
          "tokenIn":
            {
              "chainId": 80094,
              "decimals": "6",
              "address": "0x549943e04f40284185054145c6E4e9568C1D3241",
              "symbol": "USDC",
            },
          "tokenOut":
            {
              "chainId": 80094,
              "decimals": "18",
              "address": "0xFCBD14DC51f0A4d49d5E53C2E0950e0bC26d0Dce",
              "symbol": "HONEY",
            },
          "fee": "100",
          "liquidity": "1521993826513687995740",
          "sqrtRatioX96": "79246574896778039496813381592642346",
          "tickCurrent": "276328",
          "amountOut": "90189019355231301862",
        },
      ],
    ],
  "routeString": "[V3] 60.00% = WBERA -- 0.3% [0x1127f801Cb3ab7BDF8923272949AA7Dba94B5805] --> HONEY, [V3] 40.00% = WBERA -- 0.3% [0x4866Dd95a3bC4eb40Dd1B659489e3410dAe3287f] --> USDC -- 0.01% [0xb16fFD445d3c785476F87017b79423eC9057406b] --> HONEY",
  "quoteId": "616f5",
  "provider": "Kodiak",
  "params":
    {
      "tokenInAddress": "BERA",
      "tokenInChainId": 80094,
      "tokenOutAddress": "0xFCBD14DC51f0A4d49d5E53C2E0950e0bC26d0Dce",
      "tokenOutChainId": 80094,
      "amount": "100000000000000000000",
      "type": "exactIn",
      "slippageTolerance": 1,
      "recipient": "0x5a1e747482F8773fe52Cca9951E956F456EFd0Bf",
    },
  "refFee": "0",
  "otherQuote":
    {
      "amountDecimalsUSD": "225.6878516369463",
      "quoteDecimalsUSD": "225.4646160925649",
      "tokenInPriceUSD": "2.256878516369463",
      "tokenOutPriceUSD": "1",
      "priceImpact": "-0.09891340750609146",
      "methodParameters":
        {
          "calldata": "0x5ae401dc0000000000000000000000000000000000000000000000000000000068823556000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e404e45aaf0000000000000000000000006969696969696969696969696969696969696969000000000000000000000000fcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce0000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000005a1e747482f8773fe52cca9951e956f456efd0bf00000000000000000000000000000000000000000000000340aad21b3b70000000000000000000000000000000000000000000000000000742bd178e640a419f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124b858183f000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000800000000000000000000000005a1e747482f8773fe52cca9951e956f456efd0bf0000000000000000000000000000000000000000000000022b1c8c1227a00000000000000000000000000000000000000000000000000004d73b54569a90d2a100000000000000000000000000000000000000000000000000000000000000426969696969696969696969696969696969696969000bb8549943e04f40284185054145c6e4e9568c1d3241000064fcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
          "value": "0x00",
          "to": "0xe301E48F77963D3F7DbD2a4796962Bd7f3867Fb4",
        },
      "blockNumber": "8160103",
      "amount": "100000000000000000000",
      "amountDecimals": "100",
      "quote": "225464616092564905651",
      "quoteDecimals": "225.464616092564905651",
      "gasUseEstimate": "306000",
      "gasUseEstimateUSD": "6.920697896398132e-13",
      "gasPriceWei": "501981",
      "route":
        [
          [
            {
              "type": "v3-pool",
              "address": "0x1127f801Cb3ab7BDF8923272949AA7Dba94B5805",
              "tokenIn":
                {
                  "chainId": 80094,
                  "decimals": "18",
                  "address": "0x6969696969696969696969696969696969696969",
                  "symbol": "WBERA",
                },
              "tokenOut":
                {
                  "chainId": 80094,
                  "decimals": "18",
                  "address": "0xFCBD14DC51f0A4d49d5E53C2E0950e0bC26d0Dce",
                  "symbol": "HONEY",
                },
              "fee": "3000",
              "liquidity": "4493725237081532474168574",
              "sqrtRatioX96": "119153151978651141127607820981",
              "tickCurrent": "8161",
              "amountIn": "60000000000000000000",
              "amountOut": "135275596737333603789",
            },
          ],
          [
            {
              "type": "v3-pool",
              "address": "0x4866Dd95a3bC4eb40Dd1B659489e3410dAe3287f",
              "tokenIn":
                {
                  "chainId": 80094,
                  "decimals": "18",
                  "address": "0x6969696969696969696969696969696969696969",
                  "symbol": "WBERA",
                },
              "tokenOut":
                {
                  "chainId": 80094,
                  "decimals": "6",
                  "address": "0x549943e04f40284185054145c6E4e9568C1D3241",
                  "symbol": "USDC",
                },
              "fee": "3000",
              "liquidity": "718444640825350202",
              "sqrtRatioX96": "52691600443445573726226992633074205",
              "tickCurrent": "268166",
              "amountIn": "40000000000000000000",
            },
            {
              "type": "v3-pool",
              "address": "0xb16fFD445d3c785476F87017b79423eC9057406b",
              "tokenIn":
                {
                  "chainId": 80094,
                  "decimals": "6",
                  "address": "0x549943e04f40284185054145c6E4e9568C1D3241",
                  "symbol": "USDC",
                },
              "tokenOut":
                {
                  "chainId": 80094,
                  "decimals": "18",
                  "address": "0xFCBD14DC51f0A4d49d5E53C2E0950e0bC26d0Dce",
                  "symbol": "HONEY",
                },
              "fee": "100",
              "liquidity": "1521993826513687995740",
              "sqrtRatioX96": "79246574896778039496813381592642346",
              "tickCurrent": "276328",
              "amountOut": "90189019355231301862",
            },
          ],
        ],
      "routeString": "[V3] 60.00% = WBERA -- 0.3% [0x1127f801Cb3ab7BDF8923272949AA7Dba94B5805] --> HONEY, [V3] 40.00% = WBERA -- 0.3% [0x4866Dd95a3bC4eb40Dd1B659489e3410dAe3287f] --> USDC -- 0.01% [0xb16fFD445d3c785476F87017b79423eC9057406b] --> HONEY",
      "quoteId": "616f5",
      "provider": "Kodiak",
      "params":
        {
          "tokenInAddress": "BERA",
          "tokenInChainId": 80094,
          "tokenOutAddress": "0xFCBD14DC51f0A4d49d5E53C2E0950e0bC26d0Dce",
          "tokenOutChainId": 80094,
          "amount": "100000000000000000000",
          "type": "exactIn",
          "slippageTolerance": 1,
          "recipient": "0x5a1e747482F8773fe52Cca9951E956F456EFd0Bf",
        },
    },
  "expl":
    [
      {
        "provider": "Magpie",
        "status": "success",
        "executionTime": "459",
        "output": "225.505910668219988287",
        "priority": "1.00000000",
        "gas": "1977503",
      },
      {
        "provider": "Kodiak",
        "status": "success",
        "executionTime": "687",
        "output": "225.464616092564905651",
        "priority": "1.00020000",
        "gas": "306000",
      },
      {
        "provider": "OogaBooga",
        "status": "success",
        "executionTime": "732",
        "output": "225.47857060392927232",
        "priority": "1.00000000",
        "gas": "1665117",
      },
      {
        "provider": "OpenOcean",
        "status": "success",
        "executionTime": "1110",
        "output": "225.480574764869379629",
        "priority": "0.99950000",
        "gas": "561020",
      },
      {
        "provider": "Enso",
        "status": "success",
        "executionTime": "1222",
        "output": "225.47857060392926899",
        "priority": "0.99900000",
        "gas": "1141033",
      },
    ],
}

```

{% hint style="info" %}
Please note the address in `methodParameters.to`, which may change depending on the quote (mainly to use legacy Kodiak router for tokens unsupported by kX). You must approve it yourself.
{% endhint %}

{% code overflow="wrap" %}

```bash
 cast send 0x43Dac637c4383f91B4368041E7A8687da3806Cae "0xd2644d14000000000000000000000000696969696969696969696969696969696969696900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000056bc75e2d63100000000000000000000000000000fcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c19a91d0924faf6130000000000000000000000005a1e747482f8773fe52cca9951e956f456efd0bf000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000c38f339c60126deb3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e301e48f77963d3f7dbd2a4796962bd7f3867fb4000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003245ae401dc0000000000000000000000000000000000000000000000000000000068823556000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e404e45aaf0000000000000000000000006969696969696969696969696969696969696969000000000000000000000000fcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce0000000000000000000000000000000000000000000000000000000000000bb800000000000000000000000043dac637c4383f91b4368041e7a8687da3806cae00000000000000000000000000000000000000000000000340aad21b3b70000000000000000000000000000000000000000000000000000742bd178e640a419f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000043dac637c4383f91b4368041e7a8687da3806cae0000000000000000000000000000000000000000000000022b1c8c1227a00000000000000000000000000000000000000000000000000004d73b54569a90d2a100000000000000000000000000000000000000000000000000000000000000426969696969696969696969696969696969696969000bb8549943e04f40284185054145c6e4e9568c1d3241000064fcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://documentation.kodiak.finance/developers/dex/swap-api-kx.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
