1 回答

TA貢獻1770條經(jīng)驗 獲得超3個贊
如評論中所述,您必須收聽事件日志(最好針對您的地址進行過濾),并在確認后致電收據(jù)。
注意:示例只是為了演示必要的步驟。
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 關注
- 77 瀏覽
添加回答
舉報