8

I need to do some actions which need to make sure the other transactions having been confirmed already in a contract. so, Is there any method to know whether a transaction has been confirmed or not?

2 Answers 2

5

You need to check the irreversible block:

an action is irreversible (final) if "block_num" < "last_irreversible_block"

Check this out: https://github.com/EOSIO/eos/wiki/Tutorial-Exchange-Deposit-Withdraw#machine-readable-account-history-json

If you are inside the contract and have a reference of a transaction/action/receiving-action you can assume that these are going to be all confirmed or if for some reason they are not, your action will fail too.

1
  • Is there a is a difference between "confirmed" (< supermajority of block producers agree) and "irreversibly confirmed" (>= supermajority of block producers agree? If so, I'm not sure this answers the stated question although it apparently answers the intended question. See also: eosio.stackexchange.com/questions/289/…
    – kkurian
    Commented May 23, 2018 at 22:21
2

You can use the /v1/chain/push_transaction endpoint of dfuse.io documented here: https://docs.dfuse.io/#rest-api-post-push_transaction

It's a drop-in replacement for the standard /v1/chain/push_transaction endpoint, but it will not return until the transaction made it into a block (provided you pass in the X-Eos-Push-Guarantee: in-block header). It will also return the traces of execution from the actual block instead of the speculative execution from the edge node you're submitting the transaction to.

There's also support for irreversible as a value to that header, and in this case the HTTP request will wait until irreversibility of the transaction before returning. We're soon rolling out support for handoff:1 to have the request return once a series of blocks have successfully been handed off from one producer to the next, greatly increasing the probability that your transaction isn't forked out. This should have you wait between 1 to 7 seconds.

Otherwise, you can check the get_transaction_lifecycle websocket command in the same documentation linked above. If you take the transaction ID of the transaction you're submitting, you can be notified of all the state changes (block inclusion, forking, irreversibility, etc..) of a given transaction in real-time.

Hope that helps!

1
  • Is this a free service or paid?
    – Muhzin
    Commented Aug 16, 2021 at 7:06

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.