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

Mistake in "web3-eth-subscribe.html#subscribe-newblockheaders" Example

Open Remi-Burgel opened this issue 8 years ago • 3 comments

Hi, I guess I could modify this myself but I'm a newbe on github. On this page, there is a mistake in the example.

The example say :

var subscription = web3.eth.subscribe('newBlockHeaders', function(error, result){
    if (!error)
        console.log(error);
})
.on("data", function(blockHeader){
});

It means that if you have NO error your print the error. It's silly but weird to let it there.

Remi-Burgel avatar Feb 09 '18 15:02 Remi-Burgel

my issue with the example is that you have two events, the call back and the on data event and also using the callback to track the error while you can use the on error event

correct is

web3.eth
      .subscribe("newBlockHeaders")
      .on("data", transaction => {
        console.log({ transaction });
      })
      .on("error",console.error);

BransonGitomeh avatar Feb 21 '18 11:02 BransonGitomeh

Thanks, these are all options shown, you can use either the error event OR the callback.

frozeman avatar Aug 15 '18 10:08 frozeman

fixed in #1876

frozeman avatar Aug 15 '18 10:08 frozeman