4

I'm aware of using a callback in signAndSend or sign to verify if a transaction is finalized (like here: https://polkadot.js.org/docs/api/start/api.tx.subs/). Is there a way to do this after the transaction has been sent?

Or more specifically: how can I check if a transaction transfer has been completed after it has already been sent?

Thanks!

1
  • Another potential way is to use an indexer.
    – Bruno
    Commented Apr 22, 2022 at 13:48

1 Answer 1

4

There are a few things you can do:

  • If you have the extrinsic hash of the tx and its block number, using the polkadot app, you can explore the blocks and look for your transaction and check if its in block and if the execution was fine (extrinsicSuccess). But I don't think this is what you need.
  • If you know the block number where your tx is in, query the block where your transaction is registered and inspect its events to check if the tx succeed or failed. You can use the Polkadot API to query the block has using its number like:
// Get the hash of the block nº1
const blockHash = await api.rpc.chain.getBlockHash(1);
// Get the block itself
const signedBlock = await api.rpc.chain.getBlock(blockHash);
  • If you don't know your block number but know the extrinsic hash, you need to process each block (or a slice of them) until you find your extrinsic. This is needed because extrinsic hashes are not unique, but combining the block number + extrinsic hash is.
  • You can also have an event listener running all the time and processing each block in order to keep track of every transaction execution.

This page is really useful to understand how to fetch things and determine the status of a transaction https://polkadot.js.org/docs/api/cookbook/blocks, but again, as long as you have some basic information of the transaction you should be able to make some queries that retrieve what you need.

1
  • 1
    Thank you, this was very helpful! Commented Apr 28, 2022 at 15: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.