8

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

1 Answer 1

6

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.

2
  • Great! Thank you so much for this answer. So there is no way to be 100% sure, but we can be "sure enough" after a number of confirmations.
    – jeff
    Jan 17, 2017 at 3:37
  • By mathematics, that's right. For curiosity, note that even with the massive amount of work in the Bitcoin blockchain, it's still possible for someone (possibly from outer space) to come along with a blockchain that has more work, and all Bitcoin blocks (after genesis) could be reorganized. If this were to happen, the community can choose to hardfork to preserve the chain before the "intrusion".
    – eth
    Jan 17, 2017 at 3:44

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.