> ## 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.

# Virtual Environments पर WebSocket से कनेक्ट करें

> eth_subscribe और eth_unsubscribe का उपयोग करके real-time block और event updates के लिए Virtual Environment पर WebSockets के माध्यम से कनेक्ट करें।

WebSockets Virtual Environments के लिए एक efficient, real-time connection प्रदान करते हैं, जो नए blocks और events पर तुरंत updates की अनुमति देते हैं। लगातार polling की आवश्यकता को समाप्त करके, WebSockets latency और server load को कम करते हैं। वे उन dapps के लिए महत्वपूर्ण हैं जिन्हें तत्काल data की आवश्यकता होती है, जैसे DEXs और trading platforms।

Tenderly [Node RPCs](/node-rpc/overview) और [Virtual Environments](/virtual-environments/overview) दोनों के लिए websockets का समर्थन करता है, जिससे आप responsive, high-performance blockchain applications को आसानी से बना और test कर सकते हैं।

`eth_subscribe` और `eth_unsubscribe` methods का उपयोग करने के लिए WebSocket access आवश्यक है।

* `eth_subscribe`
* `eth_unsubscribe`

## Tenderly WebSockets से कनेक्ट करना

1. [Virtual Environments page](https://dashboard.tenderly.co/?redirectTo=testnets) पर जाएं
2. नया Virtual Environments बनाएं या मौजूदा एक चुनें और RPC URL कॉपी करें
3. `wscat` के साथ test करें:

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

एक बार कनेक्ट होने के बाद, आप Tenderly WebSocket को JSON-RPC requests भेज सकते हैं। आपको real time में responses मिलेंगे। उदाहरण के लिए, आप **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"]}
```

आपको कुछ इस तरह की response मिलनी चाहिए:

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