🌐 Sample WebSocket Connection with InstantNodes

Endpoint

To connect to the InstantNodes RPC node using WebSocket, use the following endpoint:
wss://solana-api.instantnodes.io/token-<your-api-key>

Code Sample

Here’s a simple WebSocket connection in JavaScript:

const WebSocket = require('ws');

const ws = new WebSocket('wss://solana-api.instantnodes.io/token-<your-api-key>

Explanation

  • wss://solana-api.instantnodes.io/token-<your-api-key>: This is the WebSocket endpoint.

  • ws.on('open'): Initiates the connection and sends a sample request.

  • ws.on('message'): Handles responses from the node.

  • ws.on('close'): Logs disconnection events.

  • ws.on('error'): Catches any connection errors.

Common Use Cases

🔹 Real-time updates: Ideal for streaming data such as block height, transaction updates, etc.

🔹 Efficient communication: WebSocket connections remain open, reducing the need for repeated HTTP requests.

© 2024 Best Architects L.L.C-FZ

© 2024 Best Architects L.L.C-FZ