getProgramAccounts - Solana

This method returns all accounts owned by a program, with optional filters on data size and byte content. This is the primary method for indexing program state such as SPL Token accounts and Anchor PDAs.

Parameters

ParameterTypeRequiredDescription
programIdstringYesBase58-encoded Pubkey of the owning program
configobjectNoConfiguration object controlling filters, encoding, and commitment

Config Object

FieldTypeRequiredDescription
encodingstringNoData encoding: base58, base64, base64+zstd, or jsonParsed
commitmentstringNoCommitment level: processed, confirmed, or finalized. Defaults to finalized
dataSliceobjectNoByte range to return, with offset and length fields
filtersarrayNoUp to 4 filter objects, each a dataSize or memcmp filter
withContextbooleanNoWrap the result in an RpcResponse context object
minContextSlotnumberNoMinimum slot the request can be evaluated at

Memcmp Filter

FieldTypeRequiredDescription
offsetnumberYesByte offset into the account data to compare from
bytesstringYesData to match, base58 or base64 encoded
encodingstringNoEncoding of the bytes field: base58 or base64

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "getProgramAccounts",
    "params": ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", {"encoding": "jsonParsed", "filters": [{"dataSize": 165}, {"memcmp": {"offset": 0, "bytes": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"}}]}],
    "id": "getblock.io"
}'

example.js

javascriptconst { Connection, PublicKey } = require('@solana/web3.js');

const connection = new Connection('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', 'confirmed');

const accounts = await connection.getParsedProgramAccounts(
  new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
  {
    filters: [
      { dataSize: 165 },
      { memcmp: { offset: 0, bytes: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' } }
    ]
  }
);

console.log(accounts.length);

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'getProgramAccounts',
        'params': ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", {"encoding": "jsonParsed", "filters": [{"dataSize": 165}, {"memcmp": {"offset": 0, "bytes": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"}}]}],
        'id': 'getblock.io'
    }
)

print(response.json()['result'])

example.rs

rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "getProgramAccounts",
            "params": ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", {"encoding": "jsonParsed", "filters": [{"dataSize": 165}, {"memcmp": {"offset": 0, "bytes": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"}}]}],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": [
        {
            "account": {
                "data": [
                    "",
                    "base64"
                ],
                "executable": false,
                "lamports": 2039280,
                "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
                "rentEpoch": 18446744073709551615,
                "space": 165
            },
            "pubkey": "3emsAVdmGKERbHjmGfQ6oZ1e35dkf5z6TmFYcCQnpB2M"
        }
    ]
}

Response Parameters

ParameterTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultarrayArray of account objects owned by the program, each with pubkey and account fields

Result Entry

FieldTypeDescription
pubkeystringBase58 Pubkey of the account
accountobjectAccount object with lamports, owner, data, executable, rentEpoch, and space

Use Cases

  • Token Holder Indexes: Enumerate every SPL Token account for a given mint
  • Anchor Discriminators: Filter PDAs by the 8-byte account discriminator at offset 0
  • Order Book Crawls: List open orders accounts owned by a DEX program
  • Stake Analysis: Query stake accounts delegated to a specific vote account
  • Protocol Dashboards: Rebuild protocol state without an off-chain indexer

Error Handling

Error CodeMessageDescription
-32602Invalid paramsMore than 4 filters, malformed memcmp bytes, or unsupported encoding
-32603Internal errorScan exceeded the node's account scan limits
-32016Minimum context slot has not been reachedThe node has not yet processed minContextSlot
-32005Node is unhealthyThe node has fallen behind the cluster tip