Skip to main content

logsSubscribe

The Solana logsSubscribe method allows you to subscribe to and receive transaction logs matching specific conditions in real time.

Usage Notes
  • Must be called via a WebSocket endpoint; HTTP is not supported.
  • If the WebSocket connection is dropped, subscriptions are automatically cancelled. You must re-subscribe upon reconnection.
  • CU is consumed based on the volume of subscribed data, so it is recommended to use appropriate filtering options to subscribe only to the data you need.

1. Request

Parameters

The log subscription 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 "logsSubscribe" here.
paramsarrayrequiredLog filter and options to subscribe to. The first element is the filter condition, and the second is a configuration object.
params[0]string or objectrequiredLog filter condition.
- "all": Subscribe to all transactions except simple vote transactions
- "allWithVotes": Subscribe to all transactions including simple vote transactions
- { "mentions": [ <string> ] }: Subscribe only to transactions mentioning a specific address (currently only one address is supported; providing multiple addresses will result in an error.)
params[1].commitmentstringoptionalSpecifies the level of block commitment.
- finalized: Queries the most recent block confirmed by a supermajority of the cluster at maximum lockout. The cluster recognizes this block as finalized.
- confirmed: Queries the most recent block voted on by a supermajority of the cluster.
- processed: Queries the node's most recent block. This block may still be skipped by the cluster.

Example

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

2. Response

Subscription Response

Upon successful subscription creation, a subscription ID is returned.

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

This subscription ID is required when calling the logsUnsubscribe method.

Notifications

Once the subscription is active, the server pushes notifications whenever a transaction matching the filter condition occurs.

Response data format:

Log Notification Example

{
"jsonrpc": "2.0",
"method": "logsNotification",
"params": {
"result": {
"context": {
"slot": 5208469
},
"value": {
"signature": "5h6xBEauJ3PK6SWCZ1PGjBvj8vDdWG3KpwATGy1ARAXFSDwt8GFXM7W5Ncn16wmqokgpiKRLuS83KUxyZyv2sUYv",
"err": null,
"logs": [
"SBF program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri success"
]
}
},
"subscription": 24040
}
}

3. How to Use

Connect to WebSocket Channel

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

Subscribe to Logs

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

Receive Notifications

  • Initial response: returns a subscription ID
  • Subsequent: receive "logsNotification" events when a matching transaction occurs

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.

Unsubscribe request:

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

Response after unsubscribe:

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