I need to display a message (in my react app) when the block count reaches a particular number. I tried using web3.eth.subscribe but MetaMask provider does not support that. So is there any other way i can listen to block updates in the blockchain (using ganache for dev).

  • An ugly way to do this where I can quickly think of (but not elegant) is to keep calling eth.getBlock() and check if the block has increased. – JBrouwer Mar 30 '18 at 13:37

One module on npm for this use is eth-block-tracker. It uses polling under the hood, but MetaMask caches redundant requests, so it’s not much worse than MetaMask’s background polling is already.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.