getProgramAccounts
The getProgramAccounts method returns all accounts owned by a specified program. This powerful method enables querying all accounts associated with a particular program, which is essential for discovering token holdings, finding NFT collections, analyzing program state, and building comprehensive data indexes.
In Solana's account model, programs (smart contracts) own the accounts they create and manage. For example, the SPL Token program owns all token accounts, and each NFT collection's program owns all accounts for NFTs in that collection. This method allows you to discover all accounts owned by a program, optionally filtered by specific criteria. It's one of the most versatile RPC methods, enabling complex queries without needing separate indexing infrastructure.
This method is heavily used by wallets (to discover all token accounts for a user), NFT platforms (to enumerate collections), DEXes (to find all market accounts), and analytics tools (to analyze program usage). The method supports powerful filtering options including memcmp (memory comparison) and dataSize filters, allowing precise queries without downloading unnecessary data. However, it can be resource-intensive, so use filters to limit results.
Parameters
parameter | type | description |
|---|---|---|
programId | string | Base-58 encoded program public key to query accounts for |
config | object | Optional configuration object |
config.commitment | string | Level of commitment: 'processed', 'confirmed', or 'finalized' (default: 'finalized') |
config.encoding | string | Encoding for account data: 'base58', 'base64', 'base64+zstd', or 'jsonParsed' (default: 'base58') |
config.dataSlice | object | Optional. Request a slice of account data. Contains 'offset' and 'length' |
config.filters | array | Optional. Filter results using dataSize and/or memcmp filters |
config.withContext | boolean | Optional. Wrap result in RpcResponse JSON object (default: false) |
config.minContextSlot | number | Optional. Minimum slot that the request can be evaluated at |
Return Object
field | type | description |
|---|---|---|
result | array | Array of account information objects with public keys |
result[].pubkey | string | The account public key as base-58 encoded string |
result[].account | object | Account information object |
result[].account.lamports | number | Number of lamports assigned to this account |
result[].account.owner | string | Base-58 encoded public key of the program this account is assigned to |
result[].account.data | array|object|string | Account data in the requested encoding |
result[].account.executable | boolean | Boolean indicating if the account contains a program |
result[].account.rentEpoch | number | The epoch at which this account will next owe rent |
Request Example
Response Example
Tip: This method can be expensive and slow without filters. Always use filters to limit results: dataSize for exact account sizes, memcmp for matching specific bytes at offsets. Example: filter token accounts by owner (offset 32) or mint (offset 0). Many RPC providers limit or disable this method due to resource usage.