Introdaction
Getting Started
RPC Endpoints
WebSocket Support
🌐 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:
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.