> ## Documentation Index
> Fetch the complete documentation index at: https://sonar-cf3aeac7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Fetch a token, its candles and its trades over REST, then stream live trades over the WebSocket.

This walkthrough uses Wrapped Ether (WETH) on Base:

* Chain: Base, `8453`
* Token: `0x4200000000000000000000000000000000000006`

No API key or sign-up is needed. The API does not currently use authentication.

> [!NOTE]
>
> `api.example.com` is a placeholder host until the public API is announced. Keep the base URL in one config value so it's easy to change.

**1. Get token details**

Call [`GET /token`](https://sonar-cf3aeac7.mintlify.site/api-reference/token/get-token) with the token `address` and the `chain`. REST accepts the chain as `8453` or `evm:8453`.

```bash cURL theme={null}
curl "https://api.example.com/api/v1/token?address=0x4200000000000000000000000000000000000006&chain=8453"
```

```javascript JavaScript theme={null}
const BASE = "https://api.example.com/api/v1";
const WETH = "0x4200000000000000000000000000000000000006";

const res = await fetch(`${BASE}/token?address=${WETH}&chain=8453`);
const body = await res.json();
if (body.status !== "success") throw new Error(`${body.code}: ${body.message}`);

console.log(body.data.symbol, body.data.priceUSD, body.data.volume24hUSD);
```

```python Python theme={null}
import requests

BASE = "https://api.example.com/api/v1"
WETH = "0x4200000000000000000000000000000000000006"

body = requests.get(f"{BASE}/token", params={"address": WETH, "chain": "evm:8453"}).json()
if body["status"] != "success":
    raise RuntimeError(f'{body["code"]}: {body["message"]}')

print(body["data"]["symbol"], body["data"]["priceUSD"], body["data"]["volume24hUSD"])
```

> [!NOTE]
>
> Run the JavaScript REST examples server-side (Node 18+ has `fetch`). Calling the REST API from a web page on another origin depends on CORS headers, which are not currently guaranteed.

Every successful REST response wraps its payload in the same envelope: `status` is `"success"` and the payload is in `data`. The response below is shortened; the real object has over 100 more fields, most of them rolling stats.

```json Response (abbreviated) theme={null}
{
  "status": "success",
  "data": {
    "address": "0x4200000000000000000000000000000000000006",
    "chainId": "evm:8453",
    "name": "Wrapped Ether",
    "symbol": "WETH",
    "decimals": 18,
    "priceUSD": 3412.57,
    "totalSupply": "182345671234567890123456",
    "liquidityUSD": 48210334.18,
    "marketCapUSD": 622264019.3,
    "priceChange24hPercentage": 6.42,
    "volume24hUSD": 2310987.64,
    "trades24h": 5730
  }
}
```

Errors use a different envelope with `status: "error"`, an HTTP-matching `statusCode`, a machine-readable `code` and a `message`. A token that has not been indexed returns `404 TOKEN_NOT_FOUND`. See [Responses and errors](https://sonar-cf3aeac7.mintlify.site/concepts/responses-and-errors.md).

> [!TIP]
>
> `totalSupply` is a string in base units (not divided by `decimals`), while USD values and prices are plain JSON numbers. See [Data formats](https://sonar-cf3aeac7.mintlify.site/concepts/data-formats.md).

**2. Fetch candles**

Call [`GET /token/ohlcv`](https://sonar-cf3aeac7.mintlify.site/api-reference/token/get-token-ohlcv) for OHLCV candles from the token's most active pool. `period` defaults to `1h` and `limit` to 500 (max 2000). Candles are returned oldest first, and `t` is the bucket start in epoch **milliseconds**.

```bash cURL theme={null}
curl "https://api.example.com/api/v1/token/ohlcv?address=0x4200000000000000000000000000000000000006&chain=8453&period=15m&limit=96"
```

```javascript JavaScript theme={null}
const params = new URLSearchParams({ address: WETH, chain: "8453", period: "15m", limit: "96" });
const { data: candles } = await (await fetch(`${BASE}/token/ohlcv?${params}`)).json();

for (const { t, o, h, l, c, v } of candles) {
  console.log(new Date(t).toISOString(), o, h, l, c, v);
}
```

```python Python theme={null}
params = {"address": WETH, "chain": "8453", "period": "15m", "limit": 96}
candles = requests.get(f"{BASE}/token/ohlcv", params=params).json()["data"]

for c in candles:
    print(c["t"], c["o"], c["h"], c["l"], c["c"], c["v"])
```

```json Response (abbreviated) theme={null}
{
  "status": "success",
  "data": [
    { "t": 1764748800000, "o": 3398.11, "h": 3411.9, "l": 3390.02, "c": 3405.02, "v": 1840221.4 },
    { "t": 1764749700000, "o": 3405.02, "h": 3420.55, "l": 3401.3, "c": 3417.8, "v": 2011873.92 }
  ]
}
```

To restrict the window, pass `from` and `to` as epoch milliseconds. Values in seconds are accepted but read as dates in 1970.

**3. Page through trades**

Call [`GET /trades`](https://sonar-cf3aeac7.mintlify.site/api-reference/trades/get-trades). Trades are newest first by default (`order=desc`), `limit` defaults to 10 (max 100), and each trade carries an opaque `cursor`.

To get the next page, pass the `cursor` of the **last** trade on the current page, with the same `order` and filters. There is no `nextCursor` or `hasMore` field: stop when a page has fewer items than `limit`.

```bash cURL theme={null}
# First page
curl "https://api.example.com/api/v1/trades?address=0x4200000000000000000000000000000000000006&chain=8453&limit=100"

# Next page: cursor = data[data.length - 1].cursor from the previous response
curl "https://api.example.com/api/v1/trades?address=0x4200000000000000000000000000000000000006&chain=8453&limit=100&cursor=<last cursor>"
```

```javascript JavaScript theme={null}
async function* allTrades(address, chain, limit = 100) {
  let cursor;
  while (true) {
    const params = new URLSearchParams({ address, chain, limit: String(limit) });
    if (cursor) params.set("cursor", cursor);

    const body = await (await fetch(`${BASE}/trades?${params}`)).json();
    if (body.status !== "success") throw new Error(`${body.code}: ${body.message}`);

    yield* body.data;
    if (body.data.length < limit) return; // last page
    cursor = body.data[body.data.length - 1].cursor;
  }
}

let n = 0;
for await (const trade of allTrades(WETH, "8453")) {
  console.log(trade.type, trade.tokenAmount, trade.tokenAmountUsd, trade.hash);
  if (++n >= 500) break;
}
```

```python Python theme={null}
def all_trades(address, chain, limit=100):
    cursor = None
    while True:
        params = {"address": address, "chain": chain, "limit": limit}
        if cursor:
            params["cursor"] = cursor
        page = requests.get(f"{BASE}/trades", params=params).json()["data"]
        yield from page
        if len(page) < limit:
            return
        cursor = page[-1]["cursor"]

for i, trade in enumerate(all_trades(WETH, "8453")):
    print(trade["type"], trade["tokenAmount"], trade["tokenAmountUsd"], trade["hash"])
    if i >= 499:
        break
```

> [!NOTE]
>
> When `address` is a token, trades come from that token's two most active pools. Pass a pool address instead to get every trade in one specific pool. See [Pagination and limits](https://sonar-cf3aeac7.mintlify.site/concepts/pagination-and-limits.md).

**4. Stream live trades**

Open a WebSocket to `wss://api.example.com/v1/ws` and subscribe to the [`fast-trade`](https://sonar-cf3aeac7.mintlify.site/websocket/channels/fast-trade) channel. On the WebSocket, `chain` **must** use the `evm:<id>` form: `"evm:8453"`. A bare `8453` is rejected.

```javascript JavaScript (Node 22+ or browser) theme={null}
const ws = new WebSocket("wss://api.example.com/v1/ws");
let lastCursor; // keep this to resume after a reconnect

ws.onopen = () => {
  ws.send(JSON.stringify({
    op: "subscribe",
    id: "weth-base",
    channel: "fast-trade",
    params: {
      chain: "evm:8453",
      token: "0x4200000000000000000000000000000000000006",
    },
  }));
};

ws.onmessage = ({ data }) => {
  const msg = JSON.parse(data);
  switch (msg.type) {
    case "welcome":
      console.log("connected", msg.connectionId);
      break;
    case "subscribed":
      console.log("subscribed at", msg.cursor);
      break;
    case "event":
      lastCursor = msg.cursor;
      console.log(msg.data.type, msg.data.tokenAmount, "WETH", `$${msg.data.tokenAmountUsd}`);
      break;
    case "cursor":
      lastCursor = msg.cursor;
      break;
    case "error":
      console.error(msg.code, msg.message, msg.details);
      break;
  }
};
```

```bash wscat theme={null}
npx wscat -c wss://api.example.com/v1/ws
# then paste:
{"op":"subscribe","id":"weth-base","channel":"fast-trade","params":{"chain":"evm:8453","token":"0x4200000000000000000000000000000000000006"}}
```

The server greets you, confirms the subscription, then sends one `event` per trade:

```json Server messages theme={null}
{"type":"welcome","connectionId":"3f0c5a2e-6d0b-4b8e-9f43-2a1d7c9e8b11","heartbeatMs":30000}
{"type":"subscribed","id":"weth-base","channel":"fast-trade","cursor":"38123456-0"}
{"type":"event","id":"weth-base","channel":"fast-trade","cursor":"38123457-0:1","data":{"token":"0x4200000000000000000000000000000000000006","tokenVs":"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913","pair":"0xd0b53d9277642d899df5c87a3966a349a798f224","poolType":"uniswap-v3","date":1764763200000,"blockNumber":38123457,"tokenPrice":3412.57,"tokenPriceVs":1,"tokenAmount":0.5,"tokenAmountVs":1706.29,"tokenAmountUsd":1706.29,"tokenNativePrice":1,"type":"buy","operation":"regular","blockchain":"Base","hash":"0x…","sender":"0x…","tokenAmountRaw":"500000000000000000","tokenAmountRawVs":"1706290000","gasFeesUSD":0.01,"timestamp":1764763200000}}
```

> [!NOTE]
>
> WETH is a quote asset on Base, so a `token` subscription to WETH delivers trades where WETH is the **base** of the pair (for example WETH/USDC), not every memecoin/WETH trade. For most tokens this makes no difference. See [`fast-trade`](https://sonar-cf3aeac7.mintlify.site/websocket/channels/fast-trade) for details, and [Cursors and resume](https://sonar-cf3aeac7.mintlify.site/websocket/cursors-and-resume.md) for reconnecting without missing trades.

## Next steps

> [card] [REST reference](https://sonar-cf3aeac7.mintlify.site/api-reference/overview.md)
>
> Every endpoint, parameter and response field.

> [card] [WebSocket protocol](https://sonar-cf3aeac7.mintlify.site/websocket/overview.md)
>
> Messages, heartbeats, cursors, limits and errors.

> [card] [Build a live price chart](https://sonar-cf3aeac7.mintlify.site/guides/live-price-chart.md)
>
> Combine REST candles with the `ohlcv` channel.

> [card] [Large trade alerts](https://sonar-cf3aeac7.mintlify.site/guides/large-trade-alerts.md)
>
> Filter every trade on a chain by USD size.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.