2

step1: I create a smart contract call transaction TX and send it to ethereum.
step2: The TX is validated and broadcast to other nodes.
step3: Evm execute the TX failed(maybe because solidity function return err, and so on).
step4: Someone else changed the contract state, my previous TX is valid now.


My question is , if I resend the TX now, would it be executed or discarded as a duplicate transaction?

If ethereum does not do duplicate check, one transaction may cycle in p2p network?

Gang Zhao
  • 126
  • 8

1 Answers1

2

Each transaction has a nonce. You must increment the nonce each time you send a transaction.

So in your scenario, let's say the first transaction had a nonce of 5. That transaction failed. The next transaction you send must have nonce 6. So you can't simply rebroadcast the same transaction—it will be rejected as having an invalid nonce—but you can make a new transaction that is identical except for an incremented nonce. That one will be eligible to be mined into a block.

user94559
  • 59,196
  • 6
  • 103
  • 103
  • Thanks. But if my first transaction with nonce 5 execute failed, my second transaction nonce would still be 5, and the two transactions are same.Is it right? – Gang Zhao Aug 24 '18 at 02:16
  • 1
    No, regardless of whether the transaction succeeded or failed, the next one needs to have an incremented nonce. – user94559 Aug 24 '18 at 02:17