to be
a problem slover

check ethereum tx status

func (t *Txn) Status() (status string, blockNumber *big.Int, err error) {
    _, pending, err := eth.EthClient.TransactionByHash(context.Background(), common.HexToHash(t.Params.Result.TxHash))
    if err != nil {
        return Unknown, nil, err
    }
    if pending {
        return Pending, nil, nil
    }
    receipt, err := eth.EthClient.TransactionReceipt(context.Background(), common.HexToHash(t.Params.Result.TxHash))
    if err != nil {
        return Unknown, nil, err
    }
    if receipt.Status == types.ReceiptStatusFailed {
        return Failed, receipt.BlockNumber, nil
    }
    return Success, receipt.BlockNumber, nil
}

context

Check ethereum tx status in go may need two queries, the first one TransactionByHash() check it’s pending or not, the second TransactionReceipt() further check it’s failed or success.

The status can be:

  • send: tx send out
  • pending: tx pending in mempool
  • success: tx success
  • failed: tx failed
  • cancel: tx canceled by user (with same nonce)
  • drop: tx dropped by miner because gas too low
赞(1) 打赏
欢迎转载,注明出处:刘世明的博客 » check ethereum tx status

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下作者

支付宝扫一扫打赏

微信扫一扫打赏