Skip to main content

programSubscribe RPC Method

(Subscription Websocket) Subscribe to a program to receive notifications when the lamports or data for a given account owned by the program changes.

Updated on
Oct 4, 2023

programSubscribe RPC Method

Parameters

program_id
string
The Pubkey encoded base-58 string
object
array
The configuration object with the following fields:
commitment
All fields are strings.
finalized
the node will query the most recent block confirmed by supermajority of the cluster as having reached maximum lockout, meaning the cluster has recognized this block as finalized.
confirmed
the node will query the most recent block that has been voted on by supermajority of the cluster.
processed
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
filters
string
The filter results using various filter objects; The account must meet all filter criteria to be included in results

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 getProgramAccounts RPC HTTP method
Request
1
const web3 = require("@solana/web3.js");
2
(async () => {
3
const publicKey = new web3.PublicKey(
4
"22Y43yTVxuUkoRKdm9thyRhQ3SdgQS7c7kB6UNCiaczD"
5
);
6
const solanaConnection = new web3.Connection("https://docs-demo.solana-mainnet.quiknode.pro/", {
7
wsEndpoint: "",
8
});
9
solanaConnection.onProgramAccountChange(
10
publicKey,
11
(updatedProgramInfo, context) =>
12
console.log("Updated program info: ", updatedProgramInfo),
13
"confirmed"
14
);
15
})();
16
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free