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

# Connect to a WebSocket on Virtual Environments

> Connect over WebSockets to a Virtual Environment for real-time block and event updates using eth_subscribe and eth_unsubscribe.

WebSockets provide an efficient, real-time connection to Virtual Environments, allowing immediate updates on new blocks and events. By eliminating the need for constant polling, WebSockets reduce latency and server load. They’re crucial for dapps requiring instant data, such as DEXs and trading platforms.

Tenderly supports websockets for both [Node RPCs](/node-rpc/overview) and [Virtual Environments](/virtual-environments/overview), enabling you to build and test responsive, high-performance blockchain applications with ease.

WebSocket access is necessary for using the `eth_subscribe` and `eth_unsubscribe` methods.

* `eth_subscribe`
* `eth_unsubscribe`

## Connecting to Tenderly WebSockets

1. Go to the [Virtual Environments page](https://dashboard.tenderly.co/?redirectTo=testnets)
2. Create a new Virtual Environments or select an existing one and copy the RPC URL
3. Test with `wscat`:

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
wscat -c wss://virtual.mainnet.rpc.tenderly.co/$VIRTUAL_TESTNET_ID
```

Once connected, you can send JSON-RPC requests to the Tenderly WebSocket. You'll receive responses in real time. For example, you can try sending an **eth\_subscribe** request:

```json title="request.json" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{"jsonrpc":"2.0","id":1,"method":"eth_subscribe","params":["newHeads"]}
```

You should receive a response that looks something like this:

```json title="response.json" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{"id":1,"jsonrpc":"2.0","result":"0x5ab4555c1620e384bfb27d9f3a01c71e"}
```
