Skip to main content

Extrnode: getProgramAccounts (beta)

As part of our RPC service enhancement, we have revamped the getProgramAccounts method, originally available in Solana HTTP, to address performance and reliability concerns associated with querying programs with a large number of accounts. This method retrieves all accounts owned by a specified program Pubkey, now providing improved functionality for developers to seamlessly obtain program account data.

Original Method Overview

The Solana HTTP's getProgramAccounts method allows developers to retrieve all accounts associated with a given program Pubkey. Users can customize their queries by specifying parameters such as commitment, encoding, filters, and more.

Performance Challenges

We identified the original method as having the highest error rate and longest response times among RPC requests. This is primarily attributed to programs with millions of accounts, resulting in data sizes measured in gigabytes. The existing implementation necessitates extensive iteration through all accounts, application of filters, and the transmission of large data sets over the network. As a consequence, single calls often take up to 5 minutes, with nodes frequently closing connections before completion.

Enhancements Implemented

To address these challenges, we have reimagined the method to support data retrieval in manageable chunks using limit and after parameters. This allows users to paginate through the results efficiently. Additionally, we have retained support for all parameters available in the original method, ensuring compatibility with existing workflows.

Handling Filtering Challenges

An important consideration is the potential misuse of filters, which could result in filtering out 100% of accounts, especially when targeting a token program. This scenario may lead to resource-intensive iterations with no data returned, posing a risk of potential DDoS attacks. To mitigate such risks, our logic is designed to actively search and return matching accounts within a time frame of 1 minute when filters are applied. In instances where no matches are found, we provide a cursor pointing to the last scanned account. Users can then submit subsequent requests, starting from the indicated cursor, effectively resuming the search from that point onward.

This iterative approach empowers users to navigate through large datasets efficiently, promoting a more resilient and responsive experience while safeguarding against potential misuse scenarios.

extr_getProgramAccounts

Returns all accounts owned by the provided program Pubkey.

Parameters

  • pubkey string
    The Pubkey of program encoded as base-58 string

  • object array
    The configuration object with the following fields:

    • after string
      Pubkey of an account to get the next page of results

    • limit integer
      Amount of accounts to return. Default: 1000

    • filters array
      Filter results using up to 4 filter objects

    • dataSlice string
      The returned account data using the provided offset: 'usize' and length: 'usize' fields; only available for base58, base64, or base64+zstd encodings

    • encoding string
      (default: json) The encoding format for account data. It can be one of base58 (slow), base64, base64+zstd or jsonParsed

Example Request

To retrieve accounts associated with a specific program, use the following curl command:

curl https://solana-mainnet.rpc.extrnode.com/{YOUR_TOKEN} -X POST -H "Content-Type: application/json" --data '{
"jsonrpc": "2.0",
"id": 1,
"method": "extr_getProgramAccounts",
"params": [
"YourProgramPubkey",
{
"after": "LastAccountPubkeyIfPaging",
"limit": 1000,
"filters": [
// Define your filters here
],
"dataSlice": {
"offset": "0",
"length": "1000"
},
"encoding": "base64"
}
]
}'

Example Response

{
"jsonrpc": "2.0",
"result": {
"cursor": "ATtrSWD71AHACcxM1P9XzX5ncrJPwVPZh5y9NKvVGi8r",
"processed_accounts": 1,
"value": [
{
"account": {
"data": {
"parsed": {
"info": {
"closeAuthority": "agsWhfJ5PPGjmzMieWY8BR5o1XRVszUBQ5uFz4CtDiJ",
"isNative": false,
"mint": "kinXdEcpDQeHPEuQnqmUgtYykqKGVFq6CeVX5iAHJq6",
"owner": "GMUukoFLobba7TbCYkd4XsFiKD54EY88aV6kHzHcwuCb",
"state": "initialized",
"tokenAmount": {
"amount": "7000000",
"decimals": 5,
"uiAmount": 70.0,
"uiAmountString": "70"
}
},
"type": "account"
},
"program": "spl-token",
"space": 165
},
"executable": false,
"lamports": 2039280,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 361,
"space": 165
},
"pubkey": "ATtrSWD71AHACcxM1P9XzX5ncrJPwVPZh5y9NKvVGi8r"
}
]
},
"id": 1
}