> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Edge Nodes

> Connect to a Codex edge node for the fastest Processed (unconfirmed) events and bars on Solana and Base.

Edge nodes are separate Codex WebSocket endpoints that deliver `Processed` (unconfirmed) events and bars faster than `wss://graph.codex.io/graphql`. Each one runs close to where its networks produce blocks, so trades reach you sooner wherever your app is hosted.

> [!NOTE]
>
> Edge nodes are in beta. They use the same API key, the same `graphql-transport-ws` protocol, and the same billing as the main endpoint. WebSockets require a Growth or Enterprise plan. [Learn more](https://dashboard.codex.io/dashboard/billing?utm_source=codex\&utm_medium=docs\&utm_campaign=concepts-edge-endpoints).

## Which edge node to use

Pick the edge node by **network**, not by where your servers are. For example, use the Solana edge node for Solana data even if your app runs in the US or Asia.

| Network | Edge node endpoint |
| - | - |
| Solana (`1399811149`) | `wss://fra.edge.codex.io/graphql` |
| Base (`8453`) | `wss://iad.edge.codex.io/graphql` |

If you send a subscription for a network to the wrong edge node, it still works, but it is relayed from the main API and gets no speed benefit.

## What the edge nodes serve

The speed benefit applies to these four subscriptions when `commitmentLevel` includes `Processed`, for a single supported network:

* [`onEventsCreated`](https://docs.codex.io/api-reference/subscriptions/oneventscreated)
* [`onTokenEventsCreated`](https://docs.codex.io/api-reference/subscriptions/ontokeneventscreated)
* [`onBarsUpdated`](https://docs.codex.io/api-reference/subscriptions/onbarsupdated) (set `quoteToken`)
* [`onTokenBarsUpdated`](https://docs.codex.io/api-reference/subscriptions/ontokenbarsupdated)

Everything else follows these rules:

* **Other subscriptions** (prices, holders, stats, balances, launchpad events, and so on) are accepted, but they are relayed from the main API. That adds a hop, so they arrive slightly **later** than on `graph.codex.io`. Keep them on the main endpoint.
* **`Confirmed` data** always comes from the main API. If you subscribe to `[Processed, Confirmed]` on an edge node, you get the Processed update from the edge node and the Confirmed update from the main API, at most once per stage. Leaving out `commitmentLevel` means `Confirmed`, the same as on the main endpoint.
* **Queries and mutations** are not accepted. Send them to `https://graph.codex.io/graphql`.
* **`Preprocessed`** is not supported. It is deprecated because `Processed` on an edge node now gives the earliest data. Use `Processed` instead.

A common setup is two connections: an edge connection for Processed events and bars, and a `graph.codex.io` connection for confirmed data and everything else.

## Connecting

### SDK

In [`@codex-data/sdk`](https://docs.codex.io/sdk) 2.4.1 or later, pass `{ useEdge: true }` as the options argument to use the Solana edge node.

```typescript theme={null}
import { Codex, EventCommitmentLevel } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

sdk.subscriptions.onTokenEventsCreated(
  {
    input: {
      tokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
      networkId: 1399811149,
    },
    commitmentLevel: [EventCommitmentLevel.Processed],
  },
  {
    next: (result) => console.log(result.data),
    error: console.error,
    complete: () => {},
  },
  { useEdge: true },
);
```

`useEdge` is experimental. It only accepts the four subscriptions above, with `Processed` in `commitmentLevel`, on Solana. Base is not supported in the SDK yet, so connect to the Base edge node directly as shown below.

### Direct WebSocket

Connect the same way you connect to the main endpoint (see [Subscriptions](https://docs.codex.io/concepts/subscriptions.md#how-it-works)), with the edge node endpoint:

```typescript graphql-ws theme={null}
import { createClient } from "graphql-ws";

const client = createClient({
  url: "wss://fra.edge.codex.io/graphql",
  connectionParams: {
    Authorization: apiKey,
  },
});

client.subscribe(
  {
    query: `
      subscription($tokenAddress: String!, $networkId: Int!) {
        onTokenEventsCreated(
          input: { tokenAddress: $tokenAddress, networkId: $networkId }
          commitmentLevel: [Processed]
        ) {
          id
          events {
            eventType
            timestamp
            transactionHash
            maker
          }
        }
      }
    `,
    variables: {
      tokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
      networkId: 1399811149,
    },
  },
  {
    next: (data) => console.log(data),
    error: (error) => console.error(error),
    complete: () => console.log("complete"),
  },
);
```

## Good to know

* **Processed data is unconfirmed.** A small number of events can be dropped or reorged out before confirmation. Use `Confirmed` from the main API when you need settled data.
* **Billing is the same.** Each delivered message costs the same as it would on `graph.codex.io` and counts against the same plan. Edge connections count toward your account's connection limit.
* **Regional feed errors.** If an edge node loses its feed for a network, the affected subscriptions end with an `EDGE_NETWORK_UNAVAILABLE` error. Other subscriptions on the connection keep running. Resubscribe, or fall back to `graph.codex.io` until it recovers.
* **Token bars.** On edge nodes, `onTokenBarsUpdated` returns the same data for `FILTERED` and `UNFILTERED` `statsType`, and the `liquidity` value refreshes at most every 30 seconds.
* **More networks.** More networks and edge nodes will be added over time. Check the [changelog](https://docs.codex.io/changelog) for updates.


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