web3.js
web3.js copied to clipboard
Mistake in "web3-eth-subscribe.html#subscribe-newblockheaders" Example
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.
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);
Thanks, these are all options shown, you can use either the error event OR the callback.
fixed in #1876