rootUnsubscribe
Unsubscribe from root notifications
Common use cases
| Cleanup on application shutdown | Cancel root subscription when closing connection or shutting down monitoring service. Essential for preventing resource leaks and ensuring clean WebSocket closure; always call before disconnecting. |
| Switch monitoring targets | Unsubscribe from one validator's root updates before subscribing to another. Prevents accumulating unnecessary subscriptions when switching between validators or RPC endpoints. |
Parameters
subscriptionId (number, required)
subscription id to cancel
Request
- wscat
- JavaScript
- Python
wscat -c wss://solana-mainnet.api.syndica.io -x '{
"jsonrpc": "2.0",
"id": 1,
"method": "rootUnsubscribe",
"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": "rootUnsubscribe",
"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": "rootUnsubscribe",
"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
What happens if I don't call rootUnsubscribe?
The subscription persists until WebSocket disconnection, consuming server resources and potentially causing memory leaks in long-running applications. Always unsubscribe when done.
Can I reuse a subscription ID after unsubscribing?
No. Each subscription ID is unique per WebSocket connection. Create a new subscription with rootSubscribe if you need to resume monitoring.
What does the boolean result mean?
true indicates successful unsubscription, false means the subscription ID wasn't found (already unsubscribed or never existed).
Related Methods
rootSubscribe
Creates root subscription. Always paired with rootUnsubscribe; every rootSubscribe should have corresponding rootUnsubscribe call for proper resource management.
slotUnsubscribe
Cancels slot subscription. Similar unsubscribe pattern; both follow standard WebSocket subscription lifecycle where unsubscribe methods take subscription ID and return boolean.