WebSocket
A persistent WebSocket connection delivers Solana PubSub notifications without repeated HTTP reads. Use it for account watchers, program activity, or transaction confirmation.
Connect
With wscat installed and SHREDS_API_KEY set, connect from your server:
wscat -c "wss://ws.ny.shreds.xyz/?api-key=$SHREDS_API_KEY"
Include your service access key in the connection URL as api-key. Other regions are listed in endpoints.
Subscribe to slots
Send this JSON message over the open socket:
{"jsonrpc":"2.0","id":1,"method":"slotSubscribe"}
The response contains a subscription ID. Notifications then arrive on the same connection. These IDs and slot values are illustrative:
{"jsonrpc":"2.0","result":42,"id":1}
{"jsonrpc":"2.0","method":"slotNotification","params":{"result":{"parent":299999999,"root":299999968,"slot":300000000},"subscription":42}}
To stop, pass the returned subscription ID on the same connection:
{"jsonrpc":"2.0","id":2,"method":"slotUnsubscribe","params":[42]}
Available subscription types
| Method | Updates |
|---|---|
accountSubscribe | Changes to one account |
programSubscribe | Changes to accounts owned by a program |
logsSubscribe | Transaction logs matching a filter |
signatureSubscribe | A signature reaching the requested commitment |
slotSubscribe | Slot progress |
rootSubscribe | Advances in the node's root |
Check your service limits before opening many subscriptions. signatureSubscribe ends after its terminal notification.
Reconnect and recover
Subscription IDs belong to their original connection. Reconnect with backoff, then recreate subscriptions from their definitions. Previous IDs cannot be reused.
WebSocket subscriptions do not provide a historical replay cursor. Reconcile with RPC after interruptions and track processed slots and signatures to detect gaps and duplicate work. For larger filtered pipelines, consider Yellowstone gRPC.