Using async await on custom promise

后端 未结 3 2026
情深已故
情深已故 2020-12-21 07:59

Im trying to use async await on a function that returns a promise but the out put im getting is Promise { }. In here im using f

3条回答
  •  半阙折子戏
    2020-12-21 08:30

    Someone might find this example from my code useful. You can wrap it in a promise and then resolve the custom promise and then call another promise to confirm the receipt of the original web3 call.

    return new Promise((resolve, reject) => {
        tokenContract.methods.approve(
            exchangeAddress, 
            BIG_NUMBER_1e50
        )
        .send({ from })
        .once('transactionHash')
        .once('receipt', receipt => resolve(receipt))
        .on('confirmation')
        .on('error', err => reject(err))
        .then( receipt => // will be fired once the receipt its mined
            console.log(receipt),
        );
    });
    

提交回复
热议问题