Skip to main content

logsUnsubscribe

The Solana logsUnsubscribe method cancels a log subscription created by logsSubscribe, stopping further transaction log notifications.

Usage Notes
  • Must be called via a WebSocket endpoint; HTTP is not supported.
  • After unsubscribing, you cannot re-subscribe using the same subscription ID. If you need a new subscription, you must call logsSubscribe again.
  • If the WebSocket connection is dropped, subscriptions are automatically cancelled, so you must re-establish subscriptions upon reconnection.

1. Request

Parameters

The log unsubscribe request accepts the following parameters.

ParameterTypeRequiredDescription
idinteger or stringrequiredA unique identifier for the request. Used by the client to match requests with responses.
jsonrpcstringrequiredThe JSON-RPC protocol version. Always set to "2.0".
methodstringrequiredThe name of the method to execute. Set to "logsUnsubscribe" here.
paramsarrayrequiredAn array containing the subscription ID of the subscription to cancel.

Example

{
"jsonrpc": "2.0",
"id": 1,
"method": "logsUnsubscribe",
"params": [24040]
}

2. Response

Success Response

Upon successful cancellation of the subscription, true is returned.

{
"jsonrpc": "2.0",
"result": true,
"id": 1
}

Error Response

If the subscription cancellation fails, an error is returned.

{
"jsonrpc": "2.0",
"error": {
"code": -32000,
"message": "Invalid subscription ID"
},
"id": 1
}

3. How to Use

Connect to WebSocket Channel

wscat -c wss://api.mainnet-beta.solana.com

Subscribe to Logs (First)

{
"jsonrpc": "2.0",
"id": 1,
"method": "logsSubscribe",
"params": [
{
"mentions": ["11111111111111111111111111111111"]
},
{
"commitment": "finalized"
}
]
}

Receive Subscription ID

{
"jsonrpc": "2.0",
"result": 24040,
"id": 1
}

Unsubscribe

There are two ways to cancel a subscription:

  1. Close the connection: Enter Ctrl+C in the terminal window to close the WebSocket connection, which automatically cancels all subscriptions.

  2. Cancel a specific subscription: Use logsUnsubscribe to cancel a specific subscription while keeping the connection open.

{
"jsonrpc": "2.0",
"id": 2,
"method": "logsUnsubscribe",
"params": [24040]
}

Confirm Unsubscribe

{
"jsonrpc": "2.0",
"result": true,
"id": 2
}