Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does ethereum handle duplicate transaction in different world state which means one tx is valid and the other not?

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?

like image 858
Gang Zhao Avatar asked Dec 08 '25 10:12

Gang Zhao


1 Answers

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.

like image 194
user94559 Avatar answered Dec 11 '25 14:12

user94559



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!