> For the complete documentation index, see [llms.txt](https://docs.coinvera.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coinvera.io/integration/solana/rpc/getmultipleaccounts.md).

# getMultipleAccounts

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

```json
{
  "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

```json
{
  "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 either `null` or an account object.

***

#### 💡 Examples

1. **Basic Info for Two Accounts**

   ```json
   {
     "method": "getMultipleAccounts",
     "params": [
       [
         "GyWcZ398VPbAfMk6P1JQTPQv8Z57W2AFFuTfZa3NBe8M",
         "4UJuvGZ7Ge8H3je63Nsb9ZRNVBAd3CG2ajibnRaVSbw5"
       ]
     ]
   }
   ```
2. **Parsed SPL Token Data**

   ```json
   {
     "method": "getMultipleAccounts",
     "params": [
       ["<tokenPubkey1>", "<tokenPubkey2>"],
       { "encoding": "jsonParsed", "commitment": "finalized" }
     ]
   }
   ```

***

**Code Examples**

{% tabs %}
{% tab title="Nodejs" %}

```javascript
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);
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

def get_multiple_accounts(rpc_url):
    try:
        response = requests.post(
            rpc_url,
            headers={
                'Content-Type': 'application/json',
            },
            json={
                'jsonrpc': '2.0',
                'id': 1,
                'method': 'getMultipleAccounts',
                'params': [
                    [
                        'GyWcZ398VPbAfMk6P1JQTPQv8Z57W2AFFuTfZa3NBe8M',
                        '4UJuvGZ7Ge8H3je63Nsb9ZRNVBAd3CG2ajibnRaVSbw5'
                    ]
                ]
            }
        )
        
        data = response.json()
        
        # Print the exact full response
        print('Full RPC Response:')
        print(json.dumps(data, indent=2))
        
        return data
        
    except Exception as error:
        print(f'Error getting health: {error}')
        return None

# Example usage
RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key'
get_multiple_accounts(RPC_URL)
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "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
