3

The following seems to poll my Ethereum node every second:

web3.eth.contract(contractAbi).at(contractAddress).allEvents(callback);

Is there a way to decrease the polling interval?

2
  • 1
    why dont you use watch or subscribe via websocket then you dont need to poll anymore?
    – Tony Dang
    Commented Sep 27, 2018 at 4:57
  • There is not. :(
    – Motoma
    Commented Sep 28, 2018 at 19:09

1 Answer 1

2
+50

Indeed you need to use WebsocketProvider, it gives you opportunity to receive notification instantly after node synchronization.

var web3 = new Web3(new Web3.providers.WebsocketProvider('wss://ropsten.infura.io/ws'));

var myContract = new web3.eth.Contract(<abi>, <address>);
myContract.events.allEvents({ fromBlock: 'latest' }, console.log);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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