OpenInfra.sh is now live - Solana infrastructure, included with every server. LEARN MORE HERE >

OpenInfra.shopeninfra.sh

WebSockets

Solana's pub-sub WebSocket API — real-time push notifications for accounts, programs, signatures, and logs.

Connecting

const ws = new WebSocket(  "wss://rpc.openinfra.sh?api-key=" + process.env.OPENINFRA_API_KEY); ws.onopen = () => {  console.log("connected");}; ws.onmessage = (ev) => {  const msg = JSON.parse(ev.data);   if ("result" in msg) {    // Subscription confirmation — msg.result is the subscription ID    console.log("subscription id:", msg.result);  } else if (msg.method === "accountNotification") {    // Account change notification    console.log("account update:", msg.params.result);  }}; ws.onerror = (err) => console.error("ws error:", err);ws.onclose = () => console.log("ws closed");

Available subscriptions

  • accountSubscribe — single account data and lamport changes.
  • programSubscribe — all accounts owned by a program.
  • logsSubscribe — transaction log messages (filtered by program or all).
  • signatureSubscribe — confirmation status for a specific transaction.
  • slotSubscribe — new slots as they are processed.
  • rootSubscribe — new root slots.
  • voteSubscribe — raw vote transactions.

Subscription pattern

Every subscription follows the same pattern: send a <method>Subscribe request, receive a numeric subscription ID in the response, then receive <method>Notification messages as updates arrive. Unsubscribe with <method>Unsubscribe passing the subscription ID.

Subscription guides