Skip to main content

WebSocket PubSub

Solana WebSocket RPC provides subscription methods over a persistent connection, documented in Solana WebSocket RPC docs.

MethodBest for
accountSubscribeWatching one account.
logsSubscribeStreaming transaction logs.
programSubscribeWatching accounts owned by a program.
slotSubscribeTracking slot progression.
signatureSubscribeWaiting for a transaction signature.
import WebSocket from 'ws';
const ws = new WebSocket(process.env.SOLANA_WS_URL ?? 'ws://127.0.0.1:8900');
ws.on('open', () => ws.send(JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'slotSubscribe' })));
warning

Subscriptions are not durable queues. Combine HTTP backfill with live sync.