> For the complete documentation index, see [llms.txt](https://docs.fastnode.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fastnode.io/real-time/websocket-api.md).

# WebSocket (WSS) API

The WebSocket API lets you subscribe to real-time blockchain events — new blocks, pending transactions, and log events — over a single persistent connection, instead of polling.

## Endpoint format

```
wss://<network>.fastnode.cc/YOUR-API-KEY
```

For example, BNB Smart Chain:

```
wss://bsc.fastnode.cc/YOUR-API-KEY
```

## Example: subscribe to new blocks (EVM)

```javascript
const ws = new WebSocket("wss://bsc.fastnode.cc/YOUR-API-KEY");

ws.onopen = () => {
  ws.send(JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "eth_subscribe",
    params: ["newHeads"],
  }));
};

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  console.log("New block:", msg.params?.result?.number);
};
```

## Subscription types (EVM)

| Subscription             | Description                                         |
| ------------------------ | --------------------------------------------------- |
| `newHeads`               | Fires on every new block header.                    |
| `logs`                   | Fires on logs matching a filter (address / topics). |
| `newPendingTransactions` | Fires on new pending transaction hashes.            |

To unsubscribe, call `eth_unsubscribe` with the subscription ID returned when you subscribed.

## Bitcoin / UTXO chains

UTXO chains use the **Blockbook WebSocket** interface with its own subscription methods (e.g. `subscribeNewBlock`, `subscribeAddresses`). See the [Bitcoin](/bitcoin-like-utxo/bitcoin.md) page for the endpoint.

{% hint style="warning" %}
WebSocket connections may be closed after a period of inactivity. Implement a reconnect-with-backoff strategy and re-establish subscriptions on reconnect.
{% endhint %}

## Connection limits

The number of concurrent WebSocket connections depends on your plan. Track active connections in the [Monitoring](/advanced/monitoring.md) dashboard.


---

# 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://docs.fastnode.io/real-time/websocket-api.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.
