> For the complete documentation index, see [llms.txt](https://developer.electroneum.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.electroneum.com/etn-sc-client/interacting-with-etn-sc/json-rpc-server/batch-requests.md).

# Batch requests

The JSON-RPC [specification](https://www.jsonrpc.org/specification#batch) outlines how clients can send multiple requests at the same time by filling the request objects in an array. This feature is implemented by Etn-sc's API and can be used to cut network delays. Batching offers visible speed-ups specially when used for fetching larger amounts of mostly independent data objects.

Below is an example for fetching a list of blocks in JS:

```javascript
import fetch from 'node-fetch';

async function main() {
  const endpoint = 'http://127.0.0.1:8545';
  const from = parseInt(process.argv[2]);
  const to = parseInt(process.argv[3]);

  const reqs = [];
  for (let i = from; i < to; i++) {
    reqs.push({
      method: 'eth_getBlockByNumber',
      params: [`0x${i.toString(16)}`, false],
      id: i - from,
      jsonrpc: '2.0'
    });
  }

  const res = await fetch(endpoint, {
    method: 'POST',
    body: JSON.stringify(reqs),
    headers: { 'Content-Type': 'application/json' }
  });
  const data = await res.json();
}

main()
  .then()
  .catch(err => console.log(err));
```

In this case there's no dependency between the requests. Often the retrieved data from one request is needed to issue a second one. Let's take the example of fetching all the receipts for a range of blocks. The JSON-RPC API provides `eth_getTransactionReceipt` which takes in a transaction hash and returns the corresponding receipt object, but no method to fetch receipt objects for a whole block. We need to get the list of transactions in a block and then call `eth_getTransactionReceipt` for each of them.

We can break this into 2 batch requests:

* First to download the list of transaction hashes for all of the blocks in our desired range
* And then to download the list of receipts objects for all of the transaction hashes

For use-cases which depend on several JSON-RPC endpoints the batching approach can get easily complicated. In that case Etn-sc offers a [GraphQL API](/etn-sc-client/interacting-with-etn-sc/graphql-server.md) which is more suitable.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developer.electroneum.com/etn-sc-client/interacting-with-etn-sc/json-rpc-server/batch-requests.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
