slotUnsubscribe
Unsubscribe from slot notifications
Common use cases
| Subscription cleanup on shutdown | Free server resources when application or monitoring component stops. Always call slotUnsubscribe in cleanup handlers to prevent resource leaks and ensure proper WebSocket lifecycle management. |
| Dynamic subscription management | Stop slot monitoring when switching between different data sources or RPC providers. Unsubscribe from current provider before subscribing to new one to avoid duplicate notifications and resource contention. |
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": "slotUnsubscribe",
"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": "slotUnsubscribe",
"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": "slotUnsubscribe",
"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 slotUnsubscribe?
The subscription remains active on the server until the WebSocket connection closes, consuming resources. Always explicitly unsubscribe for proper resource management.
Can I reuse a subscription ID after unsubscribing?
No. Each subscription ID is unique per WebSocket connection. Create a new subscription with slotSubscribe if you need to resume monitoring.
What does the boolean result mean?
The result is 'true' if the subscription was successfully cancelled, or 'false' if the subscription ID wasn't found (already unsubscribed or never existed).
Related Methods
slotSubscribe
Creates slot subscription. Always paired with slotUnsubscribe; every slotSubscribe should have a corresponding slotUnsubscribe call for proper resource management.
slotsUpdatesUnsubscribe
Cancels slotsUpdates subscription. Similar unsubscribe pattern; both follow standard WebSocket subscription lifecycle where unsubscribe methods take subscription ID and return boolean success status.