1 回答
TA贡献1770条经验 获得超3个赞
如评论中所述,您必须收听事件日志(最好针对您的地址进行过滤),并在确认后致电收据。
注意:示例只是为了演示必要的步骤。
func waitForReceipt(c *ethclient.Client, hash, addr string) (*types.Receipt, error) {
query := ethereum.FilterQuery{
Addresses: []common.Address{addr},
}
var ch = make(chan types.Log)
sub, err := c.SubscribeFilterLogs(ctx, query, ch) // subscribe to all logs for addr
if err != nil {
return nil, err
}
for confirmed := false; !confirmed; { // wait for confirmation on blockchain
select {
case err := <-sub.Err():
return nil, err
case vLog := <-ch:
if vLog.TxHash.Hex() == hash {
confirmed = true
}
}
}
return c.TransactionReceipt(ctx, hash) // call for receipt
}
- 1 回答
- 0 关注
- 59 浏览
添加回答
举报