Stream data directly to your applications with our websocket integration.
Websockets allow for two-way communication between a client and a server. Unlike traditional request-response models, Websockets keep a persistent connection open, enabling real-time data exchange. This is perfect for applications that require instant updates, such as chat apps, online games and marketplaces.
Standard Websockets
Helius supports all stable Solana Websockets. You can find a list of all these Websockets in the Solana documentation.
You can use these with your Helius WSS URL:
Mainnet βwss://mainnet.helius-rpc.com
Devnet β wss://devnet.helius-rpc.com
WebSocket methods marked as "unstable" in Solana's documentation, such as blockSubscribe, slotsUpdatesSubscribe and voteSubscribe are not supported.
Javascript Examples
Program Susbcribe
constWebSocket=require('ws');// Create a WebSocket connectionconstws=newWebSocket('wss://mainnet.helius-rpc.com/?api-key=<api-key>');// Function to send a request to the WebSocket serverfunctionsendRequest(ws) {constrequest= {"jsonrpc":"2.0","id":1,"method":"programSubscribe","params": ["6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", {"encoding":"jsonParsed" } ] };ws.send(JSON.stringify(request));}// Function to send a ping to the WebSocket serverfunctionstartPing(ws) {setInterval(() => {if (ws.readyState ===WebSocket.OPEN) {ws.ping();console.log('Ping sent'); } },30000); // Ping every 30 seconds}// Define WebSocket event handlersws.on('open',functionopen() {console.log('WebSocket is open');sendRequest(ws); // Send a request once the WebSocket is openstartPing(ws); // Start sending pings});ws.on('message',functionincoming(data) {constmessageStr=data.toString('utf8');try {constmessageObj=JSON.parse(messageStr);console.log('Received:', messageObj); } catch (e) {console.error('Failed to parse JSON:', e); }});ws.on('error',functionerror(err) {console.error('WebSocket error:', err);});ws.on('close',functionclose() {console.log('WebSocket is closed');});
Signature Subscribe
This subscription is for a single notification. The server automatically cancels it after sending the signatureNotification via the RPC.
constWebSocket=require('ws');// Create a WebSocket connectionconstws=newWebSocket('wss://mainnet.helius-rpc.com/?api-key=<api-key>');// Function to send a request to the WebSocket serverfunctionsendRequest(ws) {constrequest= {"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params": ["2EBVM6cB8vAAD93Ktr6Vd8p67XPbQzCJX47MpReuiCXJAtcjaxpvWpcg9Ege1Nr5Tk3a2GFrByT7WPBjdsTycY9b", {"commitment":"finalized","enableReceivedNotification":false } ] };ws.send(JSON.stringify(request));}// Function to send a ping to the WebSocket serverfunctionstartPing(ws) {setInterval(() => {if (ws.readyState ===WebSocket.OPEN) {ws.ping();console.log('Ping sent'); } },30000); // Ping every 30 seconds}// Define WebSocket event handlersws.on('open',functionopen() {console.log('WebSocket is open');sendRequest(ws); // Send a request once the WebSocket is openstartPing(ws); // Start sending pings});ws.on('message',functionincoming(data) {constmessageStr=data.toString('utf8');try {constmessageObj=JSON.parse(messageStr);console.log('Received:', messageObj); } catch (e) {console.error('Failed to parse JSON:', e); }});ws.on('error',functionerror(err) {console.error('WebSocket error:', err);});ws.on('close',functionclose() {console.log('WebSocket is closed');});