14

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...?

8
  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.
  • 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 '16 at 17:06
  • 1
    @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 '16 at 1:41
3

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
  • 2
    Is there any way to get Pending Transactions for an address? – Ashwani Agarwal Apr 25 '18 at 7:35
  • web3.eth.pendingTransactions, this will return the list of pending transactions. – Md Rayhanul Masud Saom Sep 16 at 4:55

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.