我为我的智能合约创建了 go 绑定,但在执行交易时遇到了问题。它仅在我明确指定txOpts.Nonce
(见注释行)时才有效。当我离开评论行时,我收到此错误:
Failed to execute transaction: failed to retrieve account nonce: json: cannot unmarshal hex number with leading zero digits into Go value of type hexutil.Uint64`
以下是相关代码:
txOpts := bind.NewKeyedTransactor(key)
//txOpts.Nonce = big.NewInt(<nonce>)
tx, err := token.MyContract(txOpts, big.NewInt(1))
if err != nil {
log.Fatalf("Failed to execute transaction: %v", err)
}
文档告诉它将从txOpts.From
when txOpts.Nonce
is检索待处理的随机数nil
。