0

I'm using a javascript library (etheremjs) to sign a transaction. When creating it, it asks for the nonce field. I researched about it and partially understood it. But my main problem is:

How do I actually get it? Is the nonce a lifetime transaction number of that wallet or just a number for a set of transactions in a period of time? Does it start at 0 or 1? Is it public? How can I know what nonce I should use for a new transaction?

2

The nonce in the main ethereum network starts at 0 for each account and increases each time a transaction originates from that account.

You can just count the outbound transactions on etherscan.io, or you can call eth_getTransactionCount (or web3.eth.getTransactionCount if you're using that) on any node. Here's a way to do it via Etherscan's API:

https://api.etherscan.io/api?module=proxy&action=eth_getTransactionCount&address=0xYourAddressHere&tag=latest&apikey=YourApiKeyToken

The result is the number of outbound transactions that have happened so far, and thus also the correct nonce to use for the next transaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.