2

I found a discussion here How do I get the number of confirmations on a transaction in geth or any other tool? that give the solution as:

web3.eth.blockNumber-web3.eth.getTransaction(<txhash>).blockNumber

I tried this formula and compared the value with the confirmation count returned by http://testnet.etherscan.io/api?module=account&action=txlist&address=0x4c... Both seems to match.

My question is how can this number be considered as confirmation? Is it the case of "longer it stays, bigger the confidence that it is genuine"?

  • Longer it stays, the more hashing power it would take to reverse it, so the more secure it becomes. (Rather than a case of it being genuine.) – Richard Horrocks Jul 25 '16 at 15:44
2

Blockchains use a proof of x system to confirm the validity of a transaction by a random miner. The miner confirms that the source of the transaction is valid. He does so by looking at the block before the actual block and see if the transaction is valid. After the block is mined it gets confirmed by all the following miners and as long as the majority is not colluding the probability that the block is valid increases with each following mined block. Therefore the older a transaction in terms of blocknumber, the more validated it is.

  • 2
    So it is something like this - The idea is that, if my transaction was included in block number 100 (just assume) and the current block number is 160, it means 60 random miners accepted the block 100 as valid and added to that chain and so you can say that I have 60 confirmations. This is all about consensus. See also [Ethereum network transaction confirmation coverage] (ethereum.stackexchange.com/questions/6453/…) – devsubhro Jul 26 '16 at 6:26
  • 1
    exactly, this is what I mean – Roland Kofler Jul 26 '16 at 7:41
  • 1
    From How can a DApp detect a fork or chain reorganization using web3.js or additional libraries?, I think one should call getTransactionReceipt() just to make sure that the transaction is still there. If yes, then we can be sure that there was no fork and since more blocks has been added, now it is almost impossible to erase the transaction and we can accept it. – devsubhro Jul 29 '16 at 12:31
  • Can the confidence level be measured as a function of the number of blocks mined since the transaction? If yes, what exactly is the function? – goodvibration Jun 18 '18 at 15:26

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.