I create go bindings for my smart contract but have an issue when executing a transaction. It only works when I explicitly specify the txOpts.Nonce
(see commented line). When I leave the line commented I get this error:
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`
Here is the relevant code:
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)
}
The documentation tells it would retrieve the pending nonce from txOpts.From
when txOpts.Nonce
is nil
.