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?
You need to check the irreversible block:
an action is irreversible (final) if "block_num" < "last_irreversible_block"
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.
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!