Important:Laserstream is currently in private beta and not yet publicly available. Access is limited, and some features may still be under development.
Overview
For those wanting standard Solana WebSockets, Laserstream (via Helius) fully supports stable methods like programSubscribe, accountSubscribe, signatureSubscribe, etc. This approach provides real-time communication without needing to poll for updates.
Note: Solana WebSocket methods labeled as “unstable” (e.g. blockSubscribe, slotsUpdatesSubscribe, voteSubscribe) are not supported on shared infrastructure. They may be enabled only on dedicated nodes.
Quickstart
1. Create a New Project
mkdir laserstream-ws-demo
cd laserstream-ws-demo
npm init -y
2. Install Dependencies
npm install ws
(This adds the ws library for Node.js WebSocket support.)
3. Obtain Your API Key
Generate a key from the .
4. Minimal Code Example
Create a file named index.js:
// index.js
const WebSocket = require('ws');
// 1. Connect to Laserstream WebSocket on Mainnet
const WS_URL = 'laserstream-ws-url';
const ws = new WebSocket(WS_URL);
// 2. Define a programSubscribe request (as an example)
function buildSubscriptionRequest() {
return {
jsonrpc: "2.0",
id: 1,
method: "programSubscribe",
params: [
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", // Program to track
{
encoding: "jsonParsed",
// fromSlot: 224339000 // Uncomment for replay from a specific slot
}
]
};
}
// 3. Keep connection alive with pings (30s interval)
function startPing(ws) {
setInterval(() => {
if (ws.readyState === WebSocket.OPEN) {
ws.ping();
console.log("Ping sent");
}
}, 30000);
}
// 4. Set up event handlers
ws.on('open', () => {
console.log("WebSocket is open");
ws.send(JSON.stringify(buildSubscriptionRequest()));
startPing(ws);
});
ws.on('message', (data) => {
try {
const msg = JSON.parse(data);
console.log("Received:", msg);
} catch (err) {
console.error("Failed to parse JSON:", err);
}
});
ws.on('error', (err) => {
console.error("WebSocket error:", err);
});
ws.on('close', () => {
console.log("WebSocket is closed");
});
4. Replace Your Endpoint and API Key
Replace the placeholder laserstream-ws-url with your actual WebSocket URL, and include your api-key as follows:
All of these standard WebSocket methods can optionally accept a fromSlot parameter in the same object as commitment and encoding. When specified, Laserstream will replay any relevant events from that slot forward until real-time. This feature is especially useful if your client was offline or disconnected and needs to catch up.