Can anyone please explain the following issue? I have a pretty simple code to fetch ETH balance using the web3
JS library. It's something like the following:
import Web3 form 'web3';
const web3 = new Web3(new Web3.providers.HttpProvider('https://api.myetherapi.com/eth'));
const batch = new web3.eth.BatchRequest();
batch.add(api.eth.getBalance.request('0x...', 'latest', (err, balance) => {
if (err) {
console.error(err);
} else {
console.log(web3.utils.fromWei(balance, 'ether');
}
}));
...
batch.execute();
I call this code every N seconds, and it works fine most of the time. However, when some transaction changes the balance, a weird thing happens: getBalance
may return either new balance or old one. I mean, one call will return a new value, the next call - old value, then new value again and so on.
Is there any kind of a workaround for this?