15

A few questions about rawTransactions:

  1. Are they documented anywhere?
  2. How exactly should I set the nonce of a rawTransaction? If I start geth, and submit nothing but rawTransactions to it, then the nonces are simply numbered 1, 2, 3, ..., correct? How about if I mix in some non-raw (sendTransaction) transactions, from a different address? For example, suppose I submit eth_sendTransaction, eth_sendTransaction, eth_sendRawTransaction. Should the nonce of the first raw transaction be 1 or 3?
  3. Has anything changed in the way rawTransaction nonces are handled, between develop and master?
  4. Does the answer to (2) change if the sendTransaction(s) and raw transactions are from different addresses?

Edited (4/2/2016): the specific error I'm getting when I attempt to send raw transactions to geth: -32000: Nonce too low. (This is why I'm so focused on the nonce value...)

Here is an example of the client-side transaction, prior to being wrapped and packaged by ethereumjs-tx:

{
  "to": "0x895d32f2db7d01ebb50053f9e48aacf26584fe40",
  "from": "0x6bcf3d525c425965a40fb77b1fe6461eeced67d7",
  "gasLimit": "0x2fd618",
  "nonce": 1,
  "value": "0x0",
  "data": "0x5f92896e00000000000000000000000000000000000000000000000000000000000f69b5",
  "gasPrice": "0x4a817c800"
}

Anything obviously wrong there...?

2 Answers 2

10
  1. A raw transaction is the RLP encoded value of a signed transaction, i.e. everything included as defined by the yellow paper page 4, section 4.2
  2. Nonces must already be included in the raw transaction, you cannot set it. Geth does not set it. (Since the signature that is also included is based on it).
  3. Not as far as I know.
2
  • 1
    Re: (2), how do you specify the correct nonce to include in the raw transaction, prior to signing it? i.e., if you are programmatically constructing a transaction in the client, then that program must set the nonce value somehow. My approach has been to use getTransactionAccount(address, "pending") but this is no longer working (on geth's develop branch).
    – tinybike
    Apr 2, 2016 at 17:06
  • 2
    @tinybike - if you were manually constructing transactions, you would most likely use getTransactionCount. Whether you decide to specify pending would be up to you. Pending would increment the nonce to one more value than the latest value stored in the pending transaction list. If you wanted to send another transaction to overwrite one of the pending ones (say, you decide your original gas price was too low and want to increase it to get it mined quicker) then you could just use the nonce of that transaction again. Whichever one gets mined first would make the other one invalid.
    – bozzle
    Jul 19, 2016 at 1:41
5

The nonce is always the sender's transaction count. Receiving a transaction doesn't affect the nonce. When a transaction is processed, all pending transactions with a nonce lower than the confirmed transaction are cancelled.

The transaction count and nonce can be set by web3.eth.getTransactionCount(). Pending transactions must be taken into account.

nonce = web3.eth.getTransactionCount() + pending transactions
3
  • 3
    Is there any way to get Pending Transactions for an address? Apr 25, 2018 at 7:35
  • 1
    web3.eth.pendingTransactions, this will return the list of pending transactions. Sep 16, 2019 at 4:55
  • 1
    @Timothy, can we use 'earliest' as the second parameter to count all transactions instead of calculating pending and done transactions separately? Mar 24, 2020 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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