Go-ethereum: Go bindings: failed to retrieve account nonce

Created on 6 Aug 2017  路  7Comments  路  Source: ethereum/go-ethereum

System information

Geth version:
Geth
Version: 1.6.7-stable
Git Commit: ab5646c532292b51e319f290afccf6a44f874372
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.8.3
Operating System: darwin
GOPATH=/Users/sebastian/go
GOROOT=/usr/local/Cellar/go/1.8.3/libexec

OS & Version: OSX

Issue description

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.

inactive

Most helpful comment

Thanks for your feedback! It is testrpc.

All 7 comments

Which API are you talking to? Is it geth, parity, testrpc?

Thanks for your feedback! It is testrpc.

I'm also encountering this issue when trying to connect to a local instance of geth through localhost:8545

Having this issue as well.

Running testrpc with verbose mode enabled (testrpc -v) reveals the potential culprit:

   > {
   >   "jsonrpc": "2.0",
   >   "id": 1,
   >   "method": "eth_getTransactionCount",
   >   "params": [
   >     "0x66c8395c515e2fcc24787d4d37d5b194d6f9401d",
   >     "pending"
   >   ],
   >   "external": true
   > }
 <   {
 <     "id": 1,
 <     "jsonrpc": "2.0",
 <     "result": "0x0c"
 <   }

(note: I replaced the account address with a dummy address in the call above)

At this stage I don't fully understand why, but testrpc gives back 0x0c as the result for the transactionCount call. This makes the ethclient.PendingNonceAt() method fail since it expects an uint64 encoded as hex but 0x0c actually means FF, NP, form feed, \f in hex...
By the way, calls to transaction count method from Truffle return correct data back...

Update: correction, it was pointed out to me that actually 0x0c is 12 in hexa. so this is not the issue.

Any updates on this issue?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JMaxU picture JMaxU  路  3Comments

prene picture prene  路  3Comments

362228416 picture 362228416  路  3Comments

freshonline picture freshonline  路  3Comments

ysqi picture ysqi  路  3Comments