[Ethereum] Can a transaction get lost

chain-reorganizationconfirmationsminingtransactions

Given that I am connected to the network with at least one peer, can I be sure that a transaction I sent will be executed (either with fail or success)? Is there a possibility that it will never make it to the blockchain, so that the sender will not spend anything? What if it was included in some block, but then the block gets orphaned? Will my transaction be "removed"?

If there is such a possibility, how to deal with it? Given that I record the TxHash, can/should I check it regularly, and if it still does not exist after a "big" number of blocks, alert the user that their transaction is not executed and they should send it again? This solution looks like it's prone to double spending. Also, from this answer I understand that a transaction can disappear and reappear much later, so the "big" amount of blocks to wait is indefinite. So how can I make sure that a transaction is included in the blockchain?

Thanks

Best Answer

Blockchains based on Proof of Work are probabilistic, and as more blocks are built upon the block containing a transaction, the probability of a chain reorganization removing that block and transaction becomes extremely low.

can/should I check it regularly, and if it still not exists after a "big" number of blocks, alert the user that their transaction is not executed and they should send it again?

Yes, and for some code see How can a DApp detect a fork or chain reorganization using web3.js or additional libraries?

On mainnet, around 12 confirmations are considered secure. (On testnets like Ropsten, the guarantees are much weaker and even 64 confirmations is insufficient).

To make sure that a transaction is included in the blockchain, make sure it has:

  • a reasonable gas price (so that miners will include it in a block)

  • sufficient gas (so that the transaction isn't reverted)

Then broadcast the transaction to a dozen peers and monitor it using multiple clients.

Related Topic