Skip to main content

logsUnsubscribe

Unsubscribe from transaction logging

Common use cases
Component unmounting in web applicationsCall 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 targetsUnsubscribe 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 cleanupBatch 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 -c wss://solana-mainnet.api.syndica.io -x '{
"jsonrpc": "2.0",
"id": 1,
"method": "logsUnsubscribe",
"params": [
0
]
}'
Network Selection

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.
Server should clean up on disconnect, but explicit unsubscribe ensures proper resource cleanup and prevents edge cases where connection stays open while subscription is inactive.
What happens if I call logsUnsubscribe with an invalid subscription ID?
Returns false (subscription not found or already cancelled). No error thrown—graceful degradation.
Common when subscription already cleaned up or never existed. Check return value to verify successful cleanup if needed.
Can I reuse a subscription ID after unsubscribing?
No, subscription IDs are single-use only.
After unsubscribing, must call logsSubscribe again to get new subscription ID. Attempting to use old ID will return false.

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.

External Resources