The accountSubscribe
method in Solana allows developers to receive real-time notifications about changes to a specific account on the Solana blockchain. This subscription-based method provides updates whenever the monitored account’s data is modified.
publicKey
- The public key of the account to monitor, as a base-58 encoded string
<commitment>
- (optional) The level of commitment desired when querying state. Default is “finalized”.
encoding
- (optional) 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)result
- An integer subscription id (needed to unsubscribe)
subscription
- An object containing account information:
lamports
- Number of lamports assigned to the accountowner
- Base-58 encoded public key of the program this account has been 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 rentaccountSubscribe
code examplesnpm install -g wscat
$ wscat -c YOUR_CHAINSTACK_WEBSOCKET_ENDPOINT
# Wait for the connection to be established
Connected (press CTRL+C to quit)
> {"jsonrpc":"2.0","id":1,"method":"accountSubscribe","params":["39azUYFWPz3VHgKCf3VChUwbpURdCHRxjWVowf5jUJjg",{"encoding":"jsonParsed","commitment":"finalized"}]}
accountSubscribe
method in Solana is essential for applications that need to monitor account state changes in real-time. Common use cases include:
Was this page helpful?