Account Filters
Account Filters
Subscribe to account updates with fine-grained filtering.
SubscribeRequestFilterAccounts
array of stringsAccount Pubkeys to monitor. Matches any pubkey in the array (logical OR).
array of stringsAccount owner Pubkeys to monitor. Matches any owner in the array (logical OR).
array of SubscribeRequestFilterAccountsFilterAdditional filters (logical AND between filters):
memcmp- match bytes at a specific offsetdatasize- match exact data sizetoken_account_state- filter for valid token account statelamports- filter by lamport balance (eq, ne, lt, gt)
booleanOnly include account updates that have a non-empty transaction signature.
If all fields are empty, all accounts are broadcast. Otherwise, fields work as logical AND, and values within arrays as logical OR.
Filter Types
Memcmp
Match bytes at a specific offset in account data:
protobuf
message SubscribeRequestFilterAccountsFilterMemcmp {
uint64 offset = 1;
oneof data {
bytes bytes = 2;
string base58 = 3;
string base64 = 4;
}
}Lamports
Filter accounts by lamport balance:
protobuf
message SubscribeRequestFilterAccountsFilterLamports {
oneof cmp {
uint64 eq = 1; // equal to
uint64 ne = 2; // not equal to
uint64 lt = 3; // less than
uint64 gt = 4; // greater than
}
}Account Update Message
accountSubscribeUpdateAccountInfoproperties
pubkeybytesAccount public key.
lamportsuint64Account balance in lamports.
ownerbytesProgram owner of the account.
executableboolWhether the account contains a program.
rent_epochuint64Next rent-due epoch.
databytesAccount data.
write_versionuint64Write version for ordering.
txn_signaturebytesTransaction signature that caused the update (optional).
slotuint64Slot in which the update occurred.
is_startupboolWhether this is an initial snapshot during startup.
Account Examples
Subscribe to a Specific Account
typescript
const request = {
accounts: {
myAccount: {
account: ["vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg"],
},
},
slots: {},
transactions: {},
transactionsStatus: {},
blocks: {},
blocksMeta: {},
entry: {},
accountsDataSlice: [],
commitment: CommitmentLevel.CONFIRMED,
};Subscribe to All Token Accounts by Owner
typescript
const request = {
accounts: {
tokenAccounts: {
owner: ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"],
filters: [{ datasize: 165 }],
},
},
slots: {},
transactions: {},
transactionsStatus: {},
blocks: {},
blocksMeta: {},
entry: {},
accountsDataSlice: [],
commitment: CommitmentLevel.CONFIRMED,
};Subscribe with Data Slicing
Receive only the first 32 bytes of account data to reduce bandwidth:
typescript
const request = {
accounts: {
myAccount: {
account: ["vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg"],
},
},
accountsDataSlice: [{ offset: 0, length: 32 }],
slots: {},
transactions: {},
transactionsStatus: {},
blocks: {},
blocksMeta: {},
entry: {},
commitment: CommitmentLevel.CONFIRMED,
};Filter by Lamport Balance
Monitor accounts with a balance greater than 1 SOL:
typescript
const request = {
accounts: {
richAccounts: {
owner: ["11111111111111111111111111111111"],
filters: [
{ lamports: { gt: 1000000000 } },
],
},
},
slots: {},
transactions: {},
transactionsStatus: {},
blocks: {},
blocksMeta: {},
entry: {},
accountsDataSlice: [],
commitment: CommitmentLevel.CONFIRMED,
};