getMultipleAccounts
Explore getMultipleAccounts: Use Cases, Examples, Parameters, Response Format, and Best Practices
The getMultipleAccounts
RPC method lets you fetch data for up to 100 accounts in a single call—dramatically reducing network overhead compared to individual getAccountInfo
requests. This batch approach improves responsiveness and scalability for applications that need to load or process many accounts at once.
✅ Common Use Cases
Batch Account Loading Retrieve data for multiple known accounts (e.g., a user’s token accounts or on-chain configuration accounts) in one request.
Portfolio Trackers Simultaneously fetch balances and states for all token accounts owned by a user.
Marketplace & NFT UIs Load details of multiple NFT or marketplace item accounts in a single call.
dApp Performance Optimization Reduce RPC calls, speed up load times, and enhance user experience when handling large sets of accounts.
🛠Request Parameters
{
"pubkeys": ["<base58Pubkey1>", "<base58Pubkey2>", …], // Required, max 100 keys
"options": { // Optional
"commitment": "processed|confirmed|finalized",
"encoding": "base64|base58|base64+zstd|jsonParsed",
"dataSlice": { "offset": <number>, "length": <number> },
"minContextSlot": <u64>
}
}
pubkeys Array of base-58 encoded public keys (max 100).
options
commitment
: Query confirmation level.encoding
: How to return account data (jsonParsed
for structured formats).dataSlice
: Fetch only a byte range (offset
+length
) for large accounts.minContextSlot
: Ensure the data is at least as recent as this slot.
📦 Response Structure
{
"context": { "slot": <u64>, "apiVersion"?: "<string>" },
"value": [
null, // if account not found or error
{
"lamports": <u64>,
"owner": "<string>",
"data": ["<encoded>", "<encoding>"] | { /* parsed JSON */ },
"executable": <boolean>,
"rentEpoch": <u64>,
"space": <u64>
},
…
]
}
context.slot: Slot at which data was retrieved.
value: Array matching the order of
pubkeys
. Each element is eithernull
or an account object.
💡 Examples
Basic Info for Two Accounts
{ "method": "getMultipleAccounts", "params": [ [ "GyWcZ398VPbAfMk6P1JQTPQv8Z57W2AFFuTfZa3NBe8M", "4UJuvGZ7Ge8H3je63Nsb9ZRNVBAd3CG2ajibnRaVSbw5" ] ] }
Parsed SPL Token Data
{ "method": "getMultipleAccounts", "params": [ ["<tokenPubkey1>", "<tokenPubkey2>"], { "encoding": "jsonParsed", "commitment": "finalized" } ] }
Code Examples
const fetch = require('node-fetch');
async function getMultipleAccounts(rpcUrl) {
try {
const response = await fetch(rpcUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getMultipleAccounts',
"params": [
[
"GyWcZ398VPbAfMk6P1JQTPQv8Z57W2AFFuTfZa3NBe8M",
"4UJuvGZ7Ge8H3je63Nsb9ZRNVBAd3CG2ajibnRaVSbw5"
]
]
}),
});
const data = await response.json();
// Print the exact full response
console.log('Full RPC Response:');
console.log(JSON.stringify(data, null, 2));
return data;
} catch (error) {
console.error('Error getting health:', error.message);
return null;
}
}
// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';
getMultipleAccounts(RPC_URL);
Example Response
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"context": {
"slot": 355370044,
"apiVersion": "2.2.7"
},
"value": [
{
"lamports": 289078906,
"data": [
"",
"base64"
],
"owner": "11111111111111111111111111111111",
"executable": false,
"rentEpoch": 18446744073709552000,
"space": 0
},
{
"lamports": 196360749,
"data": [
"",
"base64"
],
"owner": "11111111111111111111111111111111",
"executable": false,
"rentEpoch": 18446744073709552000,
"space": 0
}
]
}
}
🧠Developer Tips
100-Account Limit: You can request up to 100 accounts per call.
Partial Failures: A single failure doesn’t abort the batch—check for
null
entries.jsonParsed
Convenience: Saves manual deserialization for common programs (e.g., SPL Token).Use
dataSlice
for large accounts to minimize payload size and bandwidth.Handle Nulls Gracefully: Null indicates non-existent accounts or fetch errors—plan your UI/logic accordingly.
By batching account queries with getMultipleAccounts
, your Solana application can achieve faster load times and more efficient RPC usage.
2/2Ask ChatGPT
Last updated