logsUnsubscribe
Unsubscribe from transaction logging
Common use cases
| Component unmounting in web applications | Call logsUnsubscribe in React useEffect cleanup or Vue onUnmounted to prevent memory leaks and orphaned subscriptions. Essential for single-page applications with dynamic component mounting where subscriptions must be cleaned up when components are destroyed. |
| Switching between monitoring targets | Unsubscribe from current logs subscription before subscribing to new one to prevent accumulation of unused subscriptions. Common when user changes wallet or program being monitored in UI, ensuring only one active subscription at a time. |
| Application shutdown and cleanup | Batch unsubscribe from all active logs subscriptions to free server resources gracefully before closing WebSocket. Required for well-behaved long-running services that dynamically manage multiple subscriptions. |
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": "logsUnsubscribe",
"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": "logsUnsubscribe",
"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": "logsUnsubscribe",
"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
Do I need to call logsUnsubscribe if I'm closing the WebSocket connection?
Best practice: Yes, always explicitly unsubscribe before closing.
What happens if I call logsUnsubscribe with an invalid subscription ID?
Returns false (subscription not found or already cancelled). No error thrown—graceful degradation.
Can I reuse a subscription ID after unsubscribing?
No, subscription IDs are single-use only.
Related Methods
logsSubscribe (WebSocket)
Creates the subscription that logsUnsubscribe cancels. Returns subscription ID required for unsubscribe. Every logsSubscribe should have corresponding logsUnsubscribe for proper resource management.
accountUnsubscribe (WebSocket)
Similar cleanup pattern for account subscriptions. Same parameter (subscription ID) and return type (boolean). Use same cleanup practices as logsUnsubscribe.
programUnsubscribe (WebSocket)
Cancel programSubscribe subscriptions with identical pattern. Returns boolean indicating success. Part of standard WebSocket subscription cleanup workflow.
slotUnsubscribe (WebSocket)
Cleanup slot subscriptions using same unsubscribe pattern. Single subscription ID parameter, returns boolean. All *Unsubscribe methods follow this consistent interface.
signatureUnsubscribe (WebSocket)
Cancel signature monitoring, though signature subscriptions auto-expire after confirmation. Explicit unsubscribe still recommended for immediate cleanup before auto-expiration.