Query token program
Query SPL token accounts by mint or owner with getProgramAccounts.
Query by mint
You can query all the token accounts by mint using getProgramAccounts.
Original token program
When querying the original token program it is important to specify dataSize as 165 to ensure that you are querying only valid token accounts.
{
"jsonrpc": "2.0",
"id": 1,
"method": "getProgramAccounts",
"params": [
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
{
"filters": [
{
"dataSize": 165
},
{
"memcmp": {
"offset": 0,
"bytes": "j14XLJZSVMcUYpAfajdZRpnfHUpJieZHS4aPektLWvh"
}
}
],
"encoding": "base64"
}
]
}Token-2022
When querying Token-2022, you do not add the dataSize parameter but instead filter by the byte at offset 165.
Query by owner
The standard method for querying by owner is getTokenAccountsByOwner. You can also use getProgramAccounts to query the same data, with the added possibility of more advanced filtering.
Original token program
Token-2022
Troubleshooting
On Triton shared endpoints, a getProgramAccounts call to the Token or Token-2022 program must include a memcmp filter on the owner (offset 32) or the mint (offset 0), as in the examples above. Without one, the call is rejected with HTTP 403 and the message "Your IP or provider is blocked from this endpoint".
An endpoint that doesn't index the Token program returns this error instead:
In both cases, check that your query includes the owner or mint memcmp filter and, for the original Token program, dataSize: 165. If you are still facing errors, please contact us via our customer support channels.
Digital Assets API
For a higher level API with better filtering functions, you can also use the Digital Assets API. This API supports both traditional tokens and compressed NFTs within the same interface, allowing you to query the full set of tokens owned by a user.
Read more about the DAS API.
Contact support by clicking the chat icon in your customer dashboard Sales questions? Contact us AI agent? Read llms.txt Follow updates: Blog · X · YouTube · Telegram · GitHub
Last updated