2

When an event is triggered, you get something like this:

{
  "address": "0x0a7a177321f3b3b6e2299e621eb32e892b141b4b",
  "topics": [
"0x0d332ed5c7d6f1999116748c0eb99c740f276d879d025a5be6435fcf177785de"
  ],
  "data": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568616c6c6f000000000000000000000000000000000000000000000000000000",
  "blockNumber": "0x2f6d30",
  "transactionHash": "0x4aaf274a399ee315dc351b30b2e6ff9525996d4700c4843ec0a625512cd21fd1",
  "transactionIndex": "0x4",
  "blockHash": "0xbfad930ed694aae9fc660951ac4a309701a17e75f02087c72c3ea78431c3005e",
  "logIndex": "0x2",
  "removed": false
}

I need to know if the event has been confirmed and it won't be "reverted" (at least with a high confidence level).

What I was thinking on doing was to wait for the block referenced in blockHash to have 12 confirmations to considered the event confirmed.

In order to check the 12 confirmations, my guess is that I need to check the block by calling eth_getBlockByHash, verify the response is not null (which I guess would mean the block was discarded) and make sure that eth_blockNumber - block.number is equals or bigger than 12.

Does this process to confirm an event sounds correct?

2 Answers 2

2

Yes, waiting for block confirmations is how to ensure that an event exists.

Yes, eth_getBlockByHash will return null when a block is discarded.

There's some sample code in How can a DApp detect a fork or chain reorganization using web3.js or additional libraries? (Quality answers that are added to it will get upvoted, and may also become the accepted answer.)

0

The method most people choose for what is considered "confirmed" is waiting for an (x) amount of blocks to be mined since the transaction you are checking for.

The longer you wait, the better since it reduces the chance that a transaction becomes an "uncle'd" or is reverted.

1
  • Yes, that seems to be the way to do it. In my question I wanted to know if that applies for events as well and also if the way to do it is by checking the existence of the block, because I don't know very well what happens when a block is discarded. Is it still there with a flag indicating it was discarded or is it removed completely, meaning that calling eth_getBlockByHash will return null?
    – dgaviola
    Commented May 8, 2018 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.