blockUnsubscribe
Unsubscribe from block notifications
Common use cases
| Graceful subscription cleanup | Properly unsubscribe from blockSubscribe when your application shuts down or no longer needs block updates, freeing server resources and preventing connection leaks. |
| Dynamic subscription management | Stop and restart block subscriptions based on application state (e.g., user navigation, focus changes) to conserve bandwidth and processing resources. |
Parameters
subscriptionId (integer, required)
subscription id to cancel
Request
- wscat
- JavaScript
- Python
wscat -c wss://solana-mainnet.api.syndica.io -x '{
"jsonrpc": "2.0",
"id": 1,
"method": "blockUnsubscribe",
"params": [
0
]
}'
const ws = new WebSocket('wss://solana-mainnet.api.syndica.io');
ws.on('open', function open() {
ws.send(JSON.stringify({
"jsonrpc": "2.0",
"id": 1,
"method": "blockUnsubscribe",
"params": [
0
]
}));
});
ws.on('message', function incoming(data) {
console.log(data);
});
import websocket
import json
ws = websocket.create_connection('wss://solana-mainnet.api.syndica.io')
ws.send(json.dumps({
"jsonrpc": "2.0",
"id": 1,
"method": "blockUnsubscribe",
"params": [
0
]
}))
result = ws.recv()
print(result)
ws.close()
Replace mainnet with devnet in the URL to query devnet instead.
Response
{
"jsonrpc": "2.0",
"result": true,
"id": 1
}
Response Fields
Return value: boolean
unsubscribe success message
FAQ and Troubleshooting
When should I call blockUnsubscribe?
Always unsubscribe when you stop needing block updates—on application shutdown, component unmount, or when switching data sources. This prevents resource leaks on both client and server.
What is the subscription ID?
The numeric ID returned by blockSubscribe when you initially subscribed. Store this value to unsubscribe later.
What happens if I don't unsubscribe?
The server continues sending block notifications, wasting bandwidth and server resources. Most providers will eventually timeout idle connections, but explicit cleanup is best practice.
Can I unsubscribe from a closed connection?
No. If the websocket connection is already closed, the subscription is implicitly canceled. Only call blockUnsubscribe on active connections.
Related Methods
blockSubscribe
Creates the block subscription that this method cancels. You must call blockSubscribe first to receive the subscription ID needed for unsubscribing.
logsUnsubscribe
Unsubscribe pattern for transaction logs. Same concept—use subscription ID to cancel active subscription.
accountUnsubscribe
Unsubscribe pattern for account updates. All websocket unsubscribe methods follow the same subscription ID pattern.
External Resources
- Solana Official Documentation
- Solana Websocket API - Official RPC websocket documentation covering subscription lifecycle and cleanup patterns.