我收到上述错误,代码如下。此错误是否与web3的代码或版本有关?。无法获取交易收据。
try{
this.setState({blockNumber:"waiting.."});
this.setState({gasUsed:"waiting..."});
// get Transaction Receipt in console on click
// See: https://web3js.readthedocs.io/en/1.0/web3-eth.html#gettransactionreceipt
await web3.eth.getTransactionReceipt(this.state.transactionHash, (err, txReceipt)=>{
console.log(err,txReceipt);
this.setState({txReceipt});
}); //await for getTransactionReceipt
await this.setState({blockNumber: this.state.txReceipt.blockNumber});
await this.setState({gasUsed: this.state.txReceipt.gasUsed});
} //try
catch(error){
console.log(error);
} //catch
} //onClick
1条答案
按热度按时间vyswwuz21#
this.setState
是一个异步函数,所以当你从状态this.state.txReceipt得到值时,并不保证它存在。我会修复你的代码,请告诉它是否工作: