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

# WebSocket

> eth_subscribe for new heads and logs over wss://rpc.hypedexer.com.

Connect to `wss://rpc.hypedexer.com/<chain>/<API_KEY>` and send JSON-RPC messages, exactly as over HTTPS. Every method available over HTTPS works here too, plus `eth_subscribe` and `eth_unsubscribe`.

```javascript Node.js theme={null}
const ws = new WebSocket(`wss://rpc.hypedexer.com/hyperevm/${process.env.HYPEDEXER_API_KEY}`);

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

ws.onmessage = (e) => {
  const msg = JSON.parse(e.data);
  if (msg.method === "eth_subscription") console.log("block", parseInt(msg.params.result.number, 16));
};
```

```javascript viem theme={null}
import { createPublicClient, webSocket } from "viem";

const client = createPublicClient({
  transport: webSocket(`wss://rpc.hypedexer.com/hyperevm/${process.env.HYPEDEXER_API_KEY}`),
});

client.watchBlockNumber({ onBlockNumber: (n) => console.log("block", n) });
```

## Subscriptions

| Subscription | Notes |
| - | - |
| `newHeads` | One event per block |
| `logs` | Filter by `address` and `topics`, as in `eth_getLogs` |

## Limits and billing

* **Connections per account** and **subscriptions per connection** depend on the plan, see [Limits & monthly quota](https://docs.hypedexer.com/rpc/limits-and-quota.md). Over the limit, the handshake answers `429` or the subscription is refused with `-32005`.
* Messages you send are rate-limited and counted like HTTPS calls (`eth_subscribe` counts 1 request).
* **Each notification counts 1 request** against the monthly quota (one `newHeads` event per block, one `logs` event per matching log). A `newHeads` subscription on HyperEVM, about one block per second, uses about 2.6M requests a month. Usage is settled every few seconds, not per message.
* When the monthly quota is used up and the API credit balance is empty, the gateway sends an error and closes the connection with code `4402`.
* If the chain's node restarts, the connection closes with code `1012`: reconnect and subscribe again.


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