简体   繁体   中英

async result not resolved in web3

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?

在此处输入图像描述

你得到未定义,因为这是在你的控制台中运行的最后一条语句的返回值,你的承诺可能永远不会解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM