Monday 22 October 2018

What is Nonce?


Nonce is the number that defined to every transaction in Ethereum network. It must be increased every time you send the transaction. When you send "online" transaction in the MyEtherWallet the Nonce and Gas price are set automatically. In offline transaction you can set Nonce and Gas price. But if you set wrong Nonce (smaller or the same that the last mined transaction) then the transaction will fail... if you set Nonce too hight the transaction will wait until you don't fill all the numbers in the gap...
For what it is done? Nonce prevents accidental double spending of your money from one side. And from other side Nonce prevents good people from cheater's transactions. When they try to spend money several times that they don't have...
To get the next valid number Nonce for your transaction you can go to  MyEtherWallet and in offline transaction input your public key. For my the first wallet I've got the number "3". Or you can use API, which gives access to Ethereum ledger for instance:
If send HTTP POST request to the address: 
With body:
{"jsonrpc":"2.0","method":"eth_getTransactionCount","params": ["0x34A79a202F3712Bd3Fa30A2A7D9e0D4d87Cc8653","latest"],"id":1}
It returns the same "3":
{"jsonrpc":"2.0","id":1,"result":"0x3"}



No comments:

Post a Comment