🤔 Got questions? Schedule an office hours session.
Virtual TestNets
Interact
Connect to WebSocket

Connect to a WebSocket on Virtual TestNets

WebSockets provide an efficient, real-time connection to Virtual TestNets, 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 and Virtual TestNets, 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.

Connecting to Tenderly WebSockets

  1. Go to the Virtual TestNets page
  2. Create a new Virtual TestNets or select an existing one and copy the RPC URL
  3. Test with wscat:
example
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:

request.json
{"jsonrpc":"2.0","id":1,"method":"eth_subscribe","params":["newHeads"]}

You should receive a response that looks something like this:

response.json
{"id":1,"jsonrpc":"2.0","result":"0x5ab4555c1620e384bfb27d9f3a01c71e"}