I'm playing Ethernaut Level 3, so I wrote the following code to retrieve the "guess" value:
async do_guess => {
let no = await web3.eth.getBlockNumber()
let block = await web3.eth.getBlock(no)
let factor = new web3.utils.BN('57896044618658097711785492504343953926634992332820282019728792003956564819968')
let result = new web3.utils.BN(block.hash)
let tmp = result.div(factor)
return tmp.toString()
}
let value = await do_guess()
console.log(value)
But the value is always "undefined" somehow, does anyone know what's wrong?
You are getting undefined because that is the return value of the last statement ran in your console, your promise is likely never resolving.