Subscribing to Accounts
Subscribe requests related to streaming real-time account updates
To receive account updates we use the accounts filter of the Subscribe request. The account filter has the following structure.
Similar to the transactions filter, the first field under the accounts filter is the accountLabel
, a user-defined label that helps you identify updates, especially when working with multiple filters. The account
field specifies an array of account addresses for streaming account updates. The owner
field streams updates for accounts owned by the specified addresses. Additionally, you can refine the data further by adding filters based on memcmp values, such as bytes
and dataSize
.
The "key" at the start of all filters, (e.g. accountLabel, txnLabel) is a client-assigned label and can be set to any user-defined names.
Subscribe to account updates for a program
To stream all account updates for a program, use the account
field under the accounts filter. The owner
field should specify the program's address, as all accounts belonging to the program are owned by the program address itself.
Subscribe to account updates of an address
The account
array accepts the pool address for which updates are being streamed. This is especially useful when monitoring the state of specific accounts, such as those in liquidity pools, to track changes in real time.
Subscribe to account updates using Memory compare (memcmp)
memcmp
filters allow you to match specific portions of binary data within accounts, helping you include only those account updates that meet specific criteria. This makes them especially useful for targeting specific states or values in program-owned accounts. For instance, you can use a memcmp
filter to track liquidity pool balances, monitor token ownership, or identify program-specific flags. A memcmp
filter typically specifies three key parameters: offset
, which defines the starting byte position in the account data to compare; bytes
, the value to match at the specified offset; and Encoding (optional), which determines how the bytes are encoded, such as base64 or base58.
For instance, this subscribe request streams updates for Raydium pool accounts with a marketProgramId
equal to serum. The filter targets the marketProgramId
field of the account, ensuring updates are streamed only for matching accounts.
Last updated