⛓️ Batch Calls
This page provides info on making batch calls to our RPC nodes, enabling simultaneous requests. Batch calling is useful for scenarios requiring data from multiple blocks or transaction.
Batch calling allows you to send multiple JSON-RPC requests in a single API call. This method retrieves or sends data to multiple endpoints in one network request, streamlining your interactions with the blockchain.
- All batch requests are processed as raw node requests.
Batch calls limits
Our infrastructure currently enforces the following limits for batch calls:
- There is a hard limit of 400 calls per batch for most chains.
- The Polygon chain have a hard limit of 100 calls per batch.
- The NEAR chain does not support batch calls by default. However, we have implemented an additional layer to enable batch calls with a limit of 5 calls per batch.
The recommended batch call payload is 50 items per request.
Each JSON object in the array is counted as an individual request. For example, if you include 10 objects, you will be charged for 10 separate requests. More details in the following article
Batch Call Format
A batch call is a JSON array containing multiple JSON-RPC request objects. Each object in the array is a separate request, following the standard JSON-RPC request format.
Request example:
- The
rawBatchRpcCall
function expects the request as an array of request objects, where each request is a standard RPC request.
curl --location 'https://api.tatum.io/v3/blockchain/node/{chain-name}/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '[
{
"jsonrpc": "2.0",
"method": "METHOD_NAME_1",
"params": [PARAMS_1],
"id": 1
},
{
"jsonrpc": "2.0",
"method": "METHOD_NAME_2",
"params": [PARAMS_2],
"id": 2
}
// Additional requests can be added here
]'
const { TatumSDK, Network } = require('@tatumio/tatum');
(async () => {
const tatum = await TatumSDK.init({
network: Network.ETHEREUM,
apiKey: { v4: 'YOUR-API-KEY'}
}
)
request = [{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_blockNumber"
},
{
"jsonrpc": "2.0",
"id": 2,
"method": "eth_getBlockByNumber",
"params": [
"latest",
true
]
}]
const batchRequest = await tatum.rpc.rawBatchRpcCall(request);
console.log(batchRequest)
})();
Some blockchain networks experience degraded performance when using batch calls. This can lead to slower response times timeouts. For example, see Optimism.
Good to Know
- Ensure that each request in the batch has a unique ID.
- Verify the format and parameters of each request to avoid errors.
- Consider the server load and rate limits when making batch calls.
Updated 13 days ago