On a previous version of web3js it was just
document.write(web3.eth.blockNumber + "<br><br>");
and it outputs it in the section of the page where the script is as seen in the infura example tutorial here
But in v1.0.0 it returns "undefined" and displays that on the screen.
from the documentation the new getBlockNumber method is
web3.eth.getBlockNumber([callback])
I have tried
web3.eth.getBlockNumber(function (error, result) {
if(!error)
{
console.log(result);
document.write(result);
}
else{
console.log(error);
}
});
But that just removed all other html from the page and wrote the block number.
I just want to be able to output the current block number to the screen at a particular html element. Can anyone help me out?
I don't know javascript so web3 is obviously a bit of a struggle for me. Still struggling to wrap my head around promises, callbacks, etc.
BAsically I think my problem is not understanding why this method requires a callback, or what the callback is supposed to be.
I'd really appreciate any help. Thanks guys.