Is there a limitation on Web3.js API calls?

Viewed 1095

I am trying to traverse over blocks and get their transaction information like this:

var endOfLoop = app.web3.eth.blockNumber;
var latestBlockNumberInDb = 1;
    for (var i = latestBlockNumberInDb; i <= endOfLoop; i++) {
        var block = app.web3.eth.getBlock(i, true);
        console.log(i);
        if (block.transactions.length) { 
            /*TODO*/
            }
        else {
            /*TODO*/
            }
        }

The problem is I am correctly getting around 525-545 block and then, app.web3.eth.getBlock(i) call blocks the execution. Loop stucks there. It is not about the incoming block that possibly make the process erroneous because when I start the loop from the block 1000 it correctly fetches blocks 1000 - 1540 and stucks at 1540.

Also app.web3.eth.blockNumber is something like 3 million and anyways the problem is not about terminating loop.

The interesting thing is, iteration count over loop is not stable. It is always changing between 525-545.

I tried to put a delay between requests but that also didn't work.

Also when I double the API call as below:

var block = app.web3.eth.getBlock(i, true);
block = app.web3.eth.getBlock(i, true);

Loop iterates around 270 times.

Is there a limit for API calls? How can it be surpassed if so?

1 Answers

Some functions interact with the blockchain, these require a node.

Unless you're running a node and configured web3 to use it, it may use infura.io by default.

Infura is a paid service, they allow you some free API calls to query the blockchain before having to register, get a key and upgrade your plan if needed.

Related