programSubscribe – Solana
The programSubscribe JSON-RPC method allows clients to subscribe to notifications about accounts owned by a specified program ID.
The programSubscribe RPC Solana method listens for changes to lamports or data associated with program-owned accounts.
Notifications are sent whenever account information is updated.
Supported Networks
Mainnet
Devnet
Parameters
Required Parameters
string (required): Pubkey of the program ID (base-58 encoded).
Optional Parameters
object (optional): Configuration object containing:
commitment (string): Commitment level.
Default: finalized
filters (array): An array of filter objects for account data.
dataSize: Filter accounts with data size in bytes.
memcmp: Filter accounts by matching data at a specific offset.
encoding (string): Account data encoding format.
Supported values: base58, base64, base64+zstd, jsonParsed.
Result
The response returns a subscription ID.
Result Format
integer: The subscription ID.
Request Examples
API Endpoints
JSON-RPC Request – Subscribe to Program with Base64 Encoding
JSON-RPC Request – Subscribe to Program with JSON-Parsed Encoding
JSON-RPC Request – Subscribe to Program with Data Size Filter
Response
A successful request returns the subscription ID.
Example Response
In this response:
result: The subscription ID.
Notification Format
Notifications are sent as JSON-RPC responses containing account data.
Base58 Encoding Example
Parsed-JSON Encoding Example
Error Handling
Common programSubscribe error scenarios:
Invalid program ID: Incorrect Pubkey.
Unsupported encoding: Invalid encoding type.
Filter misconfiguration: Incorrect filter definitions.
Example Error Response
Use Cases
The Solana programSubscribe method is essential for:
Monitoring accounts owned by programs.
Tracking data changes for real-time analytics.
Building dashboards for account state tracking.
Code programSubscribe Example – Web3 Integration
Integration with Web3
Integrating Web3 programSubscribe into Solana's Core API allows developers to:
Receive real-time account updates.
Filter notifications based on custom criteria.
Optimize dApp performance through selective data streams.
Last updated