getProgramAccounts

Returns all accounts owned by the provided program public key. This is one of the most powerful RPC methods, enabling applications to scan for all accounts created by a specific program. It supports filters by data size and memcmp (memory comparison) to narrow results. This method is essential for DeFi protocols, NFT marketplaces, and any application that needs to enumerate program state across the network.

Parameters

#TypeRequiredDescription
1stringYesBase-58 encoded public key of the program to query
2objectNoConfiguration object

Configuration object fields:

FieldTypeDescription
commitmentstringCommitment level: processed, confirmed, or finalized
encodingstringData encoding: base58, base64, base64+zstd, or jsonParsed
dataSliceobjectLimit returned data: { offset: number, length: number }
filtersarrayArray of filter objects: { memcmp: { offset, bytes } } or { dataSize: number }
withContextboolWrap result in an RpcResponse with context
minContextSlotnumberMinimum slot at which the request can be evaluated

Response

Returns an array of account objects:

FieldTypeDescription
[].pubkeystringBase-58 encoded public key of the account
[].account.lamportsu64Number of lamports in the account
[].account.ownerstringProgram owner of the account
[].account.data[string, string]object
[].account.executableboolWhether the account is executable
[].account.rentEpochu64Epoch at which rent is next owed
[].account.spaceu64Data size of the account

Code Examples

cURL

1curl http://[IP_ADDRESS]:[PORT] -X POST -H "Content-Type: application/json" -d '{
2  "jsonrpc": "2.0",
3  "id": 1,
4  "method": "getProgramAccounts",
5  "params": [
6    "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
7    {
8      "encoding": "jsonParsed",
9      "filters": [
10        { "dataSize": 165 },
11        { "memcmp": { "offset": 32, "bytes": "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg" } }
12      ]
13    }
14  ]
15}'

TypeScript

1const response = await fetch("http://[IP_ADDRESS]:[PORT]", {
2  method: "POST",
3  headers: { "Content-Type": "application/json" },
4  body: JSON.stringify({
5    jsonrpc: "2.0",
6    id: 1,
7    method: "getProgramAccounts",
8    params: [
9      "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
10      {
11        encoding: "jsonParsed",
12        filters: [
13          { dataSize: 165 },
14          { memcmp: { offset: 32, bytes: "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg" } }
15        ]
16      }
17    ]
18  }),
19});
20const { result } = await response.json();
21console.log("Accounts found:", result.length);

Python

1import requests
2
3response = requests.post("http://[IP_ADDRESS]:[PORT]", json={
4    "jsonrpc": "2.0",
5    "id": 1,
6    "method": "getProgramAccounts",
7    "params": [
8        "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
9        {
10            "encoding": "jsonParsed",
11            "filters": [
12                {"dataSize": 165},
13                {"memcmp": {"offset": 32, "bytes": "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg"}}
14            ]
15        }
16    ]
17})
18result = response.json()["result"]
19print(f"Accounts found: {len(result)}")

Rust

1use reqwest::Client;
2use serde_json::json;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let client = Client::new();
7    let res = client.post("http://[IP_ADDRESS]:[PORT]")
8        .json(&json!({
9            "jsonrpc": "2.0",
10            "id": 1,
11            "method": "getProgramAccounts",
12            "params": [
13                "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
14                {
15                    "encoding": "jsonParsed",
16                    "filters": [
17                        {"dataSize": 165},
18                        {"memcmp": {"offset": 32, "bytes": "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg"}}
19                    ]
20                }
21            ]
22        }))
23        .send().await?
24        .text().await?;
25    println!("{}", res);
26    Ok(())
27}

Example Response

1{
2  "jsonrpc": "2.0",
3  "result": [
4    {
5      "pubkey": "CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD",
6      "account": {
7        "data": { "parsed": {}, "program": "spl-token", "space": 165 },
8        "executable": false,
9        "lamports": 2039280,
10        "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
11        "rentEpoch": 361,
12        "space": 165
13      }
14    }
15  ],
16  "id": 1
17}