web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Getting error in Batch request

Open alison84r opened this issue 2 years ago • 1 comments

web3.eth.getBlock.request

I am getting error in batch request. " web3.eth.getBlock.request is not a function"

My Implementation:

`async function checkTransactionCount(startBlockNumber, endBlockNumber) { const batch = new web3.BatchRequest(); const transactions = [];

for (let i = startBlockNumber; i <= endBlockNumber; i++) { const request = web3.eth.getBlock(i, function(error, block) { if (block != null && block.transactions != null && block.transactions.length !== 0) { transactions.push(...block.transactions); } }); batch.add(request); }

await batch.execute();

return transactions; }`

my version of web3 is 4.0

alison84r avatar Jun 23 '23 17:06 alison84r

@alison84r In web3 4.x this feature is not available as was in 1.x : https://docs.web3js.org/guides/web3_upgrade_guide/x/#web3-batchrequest

You may use Promise.All with multiple web3.eth desired function calls or as mentioned in above doc link. Our team planned to work on more enhanced feature for sending multiple requests in near future in 4.x.

jdevcs avatar Jun 23 '23 17:06 jdevcs