Skip to main content

accountSubscribe RPC Method

(Subscription Websocket) Subscribe to an account to receive notifications when the lamports or data for a given account public key changes.

Updated on
Oct 4, 2023

accountSubscribe RPC Method

Parameters

Pubkey
string
The public key of account to query encoded as base-58 string
object
array
The configuration 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
encoding
string
The encoding format for account data. It can be one of base58 (slow), base64, base64+zstd or jsonParsed

Returns

result
integer
The result will be an RpcResponse JSON object with id equal to the subscription id (needed to unsubscribe)
Notification Format:
The notification format is the same as seen in the getAccountInfo RPC HTTP method
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.onAccountChange(
10
publicKey,
11
(updatedAccountInfo, context) =>
12
console.log("Updated account info: ", updatedAccountInfo),
13
"confirmed"
14
);
15
})();
16
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free