Skip to main content

logsSubscribe RPC Method

(Subscription Websocket) Subscribe to transaction logging.

Updated on
Sep 20, 2024

logsSubscribe RPC Method

Parameters

filters
string
The filter criteria for the logs to receive results by account type. Only one of the following filter can be passed at a time. The following filters types are currently supported:
all
string
Subscribe to all transactions except for simple vote transactions
allWithVotes
string
subscribe to all transactions including simple vote transactions
object
object
An object with the following field:
mentions
array
Subscribe to all transactions that mention the provided Pubkey (as base-58 encoded string). The mentions field currently only supports one Pubkey string per method call. Listing additional addresses will result in an error
encoding
The encoding format for account data. It can be one of base58 (slow), base64, base64+zstd or jsonParsed
object
array
An object with the following fields:
commitment
string
The level of commitment required for the query. The options include:
finalized
string
The node will query the most recent block confirmed by the supermajority of the cluster as having reached maximum lockout, meaning the cluster has recognized this block as finalized
confirmed
string
The node will query the most recent block that has been voted on by the supermajority of the cluster
processed
string
The node will query its most recent block. Note that the block may not be complete

Returns

result
integer
The result will be an RpcResponse JSON object with id equal to the subscription id (needed to unsubscribe)
Notification Format:
object
The notification will be an RpcResponse JSON object with value equal to
signature
string
The transaction signature base58 encoded
err
object
Error if transaction failed, null if transaction succeeded
logs
array
An array of log messages the transaction instructions output during execution, null if simulation failed before the transaction was able to execute (for example due to an invalid blockhash or signature verification failure)
Request
1
const web3 = require("@solana/web3.js");
2
(async () => {
3
const publicKey = new web3.PublicKey(
4
"E645TckHQnDcavVv92Etc6xSWQaq8zzPtPRGBheviRAk"
5
);
6
const solanaConnection = new web3.Connection("https://docs-demo.solana-mainnet.quiknode.pro/", {
7
wsEndpoint: "",
8
});
9
solanaConnection.onLogs(
10
publicKey,
11
(logs, context) => console.log("Updated account info: ", logs),
12
"confirmed"
13
);
14
})();
15
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free