# Swap API (Kodiak Router)

{% hint style="warning" %}
This is for the legacy Kodiak Router (SwapRouter02).  For most users, Swap API (kX) is the better option.  Kodiak Router is primarily used by automated bots that want low-latency, high quality API.&#x20;
{% endhint %}

### 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.

{% hint style="info" %}
Make sure to use the api.kodiak.finance endpoint below - no other legacy endpoints.
{% endhint %}

**URL:**

`https://api.kodiak.finance/quote`

**Method:**\
`GET`

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

### Query Parameters

<table><thead><tr><th width="239">Parameter</th><th width="104">Required</th><th>Description</th></tr></thead><tbody><tr><td>protocols</td><td>✅</td><td>The protocols used for the swap. Possible values: <code>v2</code>, <code>v3</code>, <code>mixed</code>.</td></tr><tr><td>tokenInAddress</td><td>✅</td><td>Address of the input token for the swap.</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.</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 humman 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).</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>deadline</td><td>❌</td><td>Time in seconds until the transaction expires.</td></tr><tr><td>slippageTolerance</td><td>❌</td><td>Allowed slippage percentage as an integer (e.g., 1 for 1%).</td></tr></tbody></table>

### Example Request

{% code overflow="wrap" %}

```
GET https://api.kodiak.finance/quote?protocols=v2,v3,mixed&tokenInAddress=0x7507c1dc16935B82698e4C63f2746A2fCf994dF8&tokenInChainId=80084&tokenOutAddress=0x1740F679325ef3686B2f574e392007A92e4BeD41&tokenOutChainId=80084&amount=40862354775778842528071&type=exactIn&recipient=0xA54e745BFf14816Ec6D323d894E7861b6Ef3F2aE&deadline=1000&slippageTolerance=1
```

{% endcode %}

### Example response

```json
{
  "blockNumber": "7067071",
  "amount": "1000000000000000000000",
  "amountDecimals": "1000",
  "quote": "55837913683147237796",
  "quoteDecimals": "55.837913683147237796",
  "quoteGasAdjusted": "55840267836750092796",
  "quoteGasAdjustedDecimals": "55.840267836750092796",
  "gasUseEstimateQuote": "2354153602855000",
  "gasUseEstimateQuoteDecimals": "0.002354153602855",
  "gasUseEstimate": "443000",
  "gasUseEstimateUSD": "0.041844",
  "gasPriceWei": "5314116485",
  "route": [
    [
      {
        "type": "v3-pool",
        "address": "0x8a960A6e5f224D0a88BaD10463bDAD161b68C144",
        "tokenIn": {
          "chainId": 80084,
          "decimals": "18",
          "address": "0x7507c1dc16935B82698e4C63f2746A2fCf994dF8",
          "symbol": "WBERA"
        },
        "tokenOut": {
          "chainId": 80084,
          "decimals": "18",
          "address": "0x0E4aaF1351de4c0264C5c7056Ef3777b41BD8e03",
          "symbol": "HONEY"
        },
        "fee": "3000",
        "liquidity": "2436507486332335185500775",
        "sqrtRatioX96": "18720675063184587718540484748",
        "tickCurrent": "-28856",
        "amountIn": "53049022487390937786",
        "amountOut": "950000000000000000000"
      }
    ],
    [
      {
        "type": "v3-pool",
        "address": "0xe49E094fe1679624C3981EB821fA6aB46c99E18E",
        "tokenIn": {
          "chainId": 80084,
          "decimals": "18",
          "address": "0x7507c1dc16935B82698e4C63f2746A2fCf994dF8",
          "symbol": "WBERA"
        },
        "tokenOut": {
          "chainId": 80084,
          "decimals": "18",
          "address": "0x0E4aaF1351de4c0264C5c7056Ef3777b41BD8e03",
          "symbol": "HONEY"
        },
        "fee": "500",
        "liquidity": "1785423513716355823391",
        "sqrtRatioX96": "18718672899386852222700719036",
        "tickCurrent": "-28858",
        "amountIn": "2788891195756300010",
        "amountOut": "50000000000000000000"
      }
    ]
  ],
  "routeString": "[V3] 95.00% = WBERA -- 0.3% [0x8a960A6e5f224D0a88BaD10463bDAD161b68C144] --\u003E HONEY, [V3] 5.00% = WBERA -- 0.05% [0xe49E094fe1679624C3981EB821fA6aB46c99E18E] --\u003E HONEY",
  "quoteId": "a6d10"
}
```

### Execution of swap

If you specified the parameters a, b, c then the answer will return the calldata property. To perform this swap you just need to use our `SwapRouter02`

`SwapRouter02` address: `0xe301E48F77963D3F7DbD2a4796962Bd7f3867Fb4`

{% hint style="warning" %}
Make sure you do the approve before the action in the example
{% endhint %}

{% code overflow="wrap" %}

```bash
 cast send 0x496e305C03909ae382974cAcA4c580E1BF32afBE "0x5ae401dc0000000000000000000000000000000000000000000000000000000067479f3a00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e404e45aaf0000000000000000000000007507c1dc16935b82698e4c63f2746a2fcf994df80000000000000000000000001740f679325ef3686b2f574e392007a92e4bed410000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000a54e745bff14816ec6d323d894e7861b6ef3f2ae0000000000000000000000000000000000000000000008a72716c2895c8a4947000000000000000000000000000000000000000000005f726aca12c4ec97acd7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
```

{% endcode %}
