> For the complete documentation index, see [llms.txt](https://router.foreverlong.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://router.foreverlong.io/swap-api/guide.md). Agents can also search and read this documentation through its [MCP server](https://router.foreverlong.io/~gitbook/mcp).

# Guide

This guide walks through the process of executing a swap using the Everlong Router Swap API.

***

### 1. Obtain an API Key <a href="#id-1.-obtain-an-api-key" id="id-1.-obtain-an-api-key"></a>

All requests to the Everlong Swap API require an API key.

The API is currently available by request only. To obtain API keys, contact the team directly on:

Telegram: [@kob\_class](http://t.me/kob_class) or [@makoveli0bkup](https://t.me/makoveli0bkup)

The key must be included in the request header:

```
x-api-key: <your-api-key>
```

If the key is missing or invalid the API returns:

```
401 Unauthorized
```

### 2. Check Token Allowances <a href="#id-2.-check-token-allowances" id="id-2.-check-token-allowances"></a>

Before executing a swap, the router must be approved to spend the input token (tokenIn).

For ERC-20 tokens, verify that the wallet has granted sufficient allowance to the Everlong Router contract.

This can be checked by calling the allowance function on the ERC-20 token contract

Example Allowance

<a class="button secondary">Copy</a>

```
await client.readContract({
  address: tokenIn,
  abi: erc20Abi,
  functionName: "allowance",
  args: [
    YOUR_ADDRESS, 
     EVERLONG_ROUTER_ADDRESS
  ]
})
```

### 3. Approve the Router <a href="#id-3.-approve-the-router" id="id-3.-approve-the-router"></a>

If the allowance is insufficient, send an approval transaction to the token contract.

A common pattern is to approve maxUint256 so future swaps do not require additional approvals.

Example approval:

```
await client.writeContract({
  address: tokenIn,
  abi: erc20Abi,
  functionName: "approve",
  args: [
    EVERLONG_ROUTER_ADDRESS,
    maxUint256
  ]
})
```

### 4. Build the Swap Transaction <a href="#id-4.-build-the-swap-transaction" id="id-4.-build-the-swap-transaction"></a>

To execute the swap, request the swap endpoint which returns transaction calldata.

```
curl "https://swap.foreverlong.io/v1/swap?tokenIn=0x...&tokenOut=0x...&amountIn=1000000000000000000&recipient=0x...&slippage=50" \
  -H "x-api-key: <your-api-key>"
```

The API response includes a transaction payload ready to be submitted on-chain.

Example response:

```
{
  "status": "Ok",
  "tokens": [
    {
      "address": "0x0f26bbb8962d73bc891327f14db5162d5279899f",
      "symbol": "TOKENA",
      "name": "Token A",
      "decimals": 18
    },
    {
      "address": "0x0913da6da4b42f538b445599b46bb4622342cf52",
      "symbol": "TOKENB",
      "name": "Token B",
      "decimals": 18
    }
  ],
  "tokenFrom": 0,
  "tokenTo": 1,
  "swapPrice": 0.987,
  "priceImpact": 0.0031,
  "amountIn": "1000000000000000000",
  "assumedAmountOut": "987000000000000000",
  "computeTimeMs": 15,
  "tx": {
    "from": "0x1111111111111111111111111111111111111111",
    "to": "0x2222222222222222222222222222222222222222",
    "data": "0x..."
  }
}
```

### 5. Execute the Swap <a href="#id-5.-execute-the-swap" id="id-5.-execute-the-swap"></a>

Once the transaction payload is returned, submit it using your wallet or backend signer.

Example using viem:

```
await client.sendTransaction({
  account,
  to: tx.to,
  data: tx.data
})
```

This transaction executes the swap through the Everlong Router, using the optimal route computed by the API.

### Notes <a href="#notes" id="notes"></a>

* amountIn must be provided in token base units (wei).
* Always validate status before executing the transaction.
* Do not modify the calldata returned by the API.
