0

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?

enter image description here

TylerH
  • 20,799
  • 66
  • 75
  • 101
daisy
  • 22,498
  • 29
  • 129
  • 265

1 Answers1

0

You are getting undefined because that is the return value of the last statement ran in your console, your promise is likely never resolving.

php_nub_qq
  • 15,199
  • 21
  • 74
  • 144