Batch request is now compatible with Ethereum

What is a batch request?

Batch request is different from traditional single jsonRPC requests, as it involves sending multiple requests within an array as a single request. In some scenarios, batch request is the only solution to solve the problem, but in some scenarios, it is not. For example, when it is necessary to send multiple requests in a short amount of time and sending them concurrently would result in rate limiting.

It's important to keep in mind that the performance of sending multiple requests concurrently doesn't always fall short of that of using batch request.

Limitations of batch request

Over HTTP

When using BlockVision's node to send batch requests over HTTP, it is important to note that each batch cannot contain more than 1000 sub-requests. Going beyond this limit can lead to instability.

Over WebSockets

When using a WebSocket connection to send JSON-RPC batch requests the maximum number of requests that can be included in a single batch is limited to 20.

CU Charging Rules of batch request

When you send requests through batch request, the CU of the batch is the sum of the CU of all requests in the batch.If an unknown method is mixed in the batch, it will be charged at a flat rate of 5 CU. It is important to keep in mind that when using batch requests, if a request is recognized, CU will be charged for it regardless of whether the request is successfully processed or not , as it may fail due to incorrect parameters passed. In such cases, it is the user's responsibility to ensure the accuracy of the parameters before making the request.

How to use

You can send individual batch requests via HTTP requests, as well as via libraries such as ethers.js or web3.js.

curl https://eth-mainnet.blockvision.org/v1/<api-key> \
-X POST \
-H "Content-Type: application/json" \
-d '[{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": []},
{"jsonrpc": "2.0", "id": 2, "method": "eth_chainId", "params": []},
{"jsonrpc": "2.0", "id": 3, "method": "eth_gasPrice", "params": []}]'