The programSubscribe
method in Solana allows developers to receive real-time notifications about changes to all accounts owned by a specific program. This subscription-based method provides updates whenever any account owned by the monitored program is modified.
publicKey
- The program ID (public key) to monitor, as a base-58 encoded string
<config>
- (optional) Configuration object:
encoding
- Data encoding for the account data:
"base58"
- Base-58 encoding (default)"base64"
- Base-64 encoding"base64+zstd"
- Compressed Base-64 encoding"jsonParsed"
- JSON format (if program supports it)filters
- (optional) Array of filter objects:
memcmp
- Filter for memory comparison:
offset
- Number of bytes into program account to start comparisonbytes
- Data to match, as base-58 encoded stringdataSize
- Filter for program account data size
commitment
- (optional) The level of commitment desired when querying state. Default is “finalized”.
result
- An integer subscription id (needed to unsubscribe)
subscription
- An object containing account information:
pubkey
- The public key of the account that changed
account
- Account information:
lamports
- Number of lamports assigned to the accountowner
- Base-58 encoded public key of the program this account is assigned todata
- Account data, encoded according to specified encoding parameterexecutable
- Boolean indicating if the account contains a programrentEpoch
- The epoch at which this account will next owe rentprogramSubscribe
code examplesnpm install -g wscat
programSubscribe
method is particularly useful for applications that need to monitor all accounts associated with a specific program. Common use cases include: