4

Web3.js docs state that a confirmation event will be fired:

  • 12 times when calling web3.eth.sendTransaction (see here)
  • 24 times when calling myContract.methods.myMethod.send (see here)

Why is the difference in the number of times that the event is fired in each case?

More importantly, what exactly should I use these events for?

At present, I simply await for the function to complete, and then use the returned value, which is a resolved Promise containing the transaction receipt (unless we're dealing with a contract deployment, in which case it will contain the new contract's instance).

To my understanding, this receipt can also be obtained using:

myContract.methods.myMethod().send().on('receipt', function(receipt){...});

I assume that this additional way of obtaining the receipt is for when you also want to handle other things, such as those confirmation events, which from what I've observed, do not necessarily occur before the receipt is available.

Do I need to count up 12 (or 24) events in order to be sure that the information receipt reflects the block-chain?

Thank you!

  • When your transaction is mined, receipt will become available.... this is confirmation 0, as more blocks added into blockchain.... confidence increases that your transaction is on longest chain and can’t be undone... – kherwa Jun 18 '18 at 15:08
  • @kherwa: Thank you. And does that confidence reach 100% after 12 (or 24) confirmation events? Or more generally, can the confidence level be measured as a function of the confirmation number? If yes, what exactly is the function? Also, does each confirmation event correspond to 1 block being added to the chain? – goodvibration Jun 18 '18 at 15:21
  • Yes each confirmation is a new block... it is upto you to wait for certain number of confirmations depending upon nature and sensitivity of transaction... – kherwa Jun 18 '18 at 15:37
  • @goodvibration so how you come up a solution, how are you making sure the transaction is completed. – faizan baig Jan 31 at 14:09
4

When a transaction is mined, the receipt is available for use, at this point confirmation number is 0, as more block are added to the blockchain, confirmation number increases. With higher confirmation number, we will have more confidence that transaction is on the longest path and can’t be undone.

Suppose you accept transactions with a certain number of confirmations, you can filter that confirmation number on confirmation event.

.on('confirmation', function(confirmationNumber,receipt){})

Regarding why the event is emitted up to 12 and 24 confirmations in different scenarios, I do not have much idea.

  • 3
    A confirmation event is fired 24 times in both cases (I tested it). The "12" is an error in the docs. Thank you! – goodvibration Jun 19 '18 at 7:04

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.