5

In my application, I need to fire multiple transactions from same address, and want to create statusCheck() function, which will let me know how many transactions of total are still pending to be added to block. Is it possible?

In my usecase, there is need to fire multiple transactions signed by same stash. There are lots of transactions, and they take lots of blocks before all of them are finalized. (As each transaction is a batch transaction, I see only one transaction getting added in one block at a time. Hence N transaction takes N blocks to complete all transactions).

For simplicity at Javascript side, I can not make JS code to wait for events from each transaction to return "status.isFinalized". Instead, after firing all N transactions, I want to write statusCheck() function, which when called will find how many transactions are yet pending to be finalized. That way, top level APP can call this statusCheck() again and again to find % completion (number of transactions pending / all transactions).

I am firing transactions by calling api.tx.utility.batch(txs).signAndSend. I tried using api.query.system.account and api.rpc.system.accountNextIndex, but they give nonce which include "pending transactions" as well. Is there way to find out when a specific transaction/nonce gets confirmed/finalized? Thanks for help guys.

2 Answers 2

12

The author_pendingExtrinsics RPC provides the list of pending extrinsics that is in the pool.

This is retrieved on a per-node basis, i.e. it will list the extrinsics that is available for the specific RPC node you are connecting to. (Some other nodes may have transactions that have not propagated to your RPC node)

If a transaction is not pending, assuming you submitted to the same RPC node, it is either included or has been removed from the pool, i.e. it could have been stale. To explicitly see what is included in a block, check new blocks and check for the extrinsic details of those processed.

2
  • thanks @jaco for reply. Sure will try this out. Is there any way, we can fine transaction status at specific 'nonce' ? That would have been clean solution.
    – pravin k
    Commented Apr 4, 2022 at 2:42
  • 1
    I believe this relates to the nonce - substrate.stackexchange.com/questions/894/… (there is no specific Substrate RPC that exposes this information)
    – Luna
    Commented Apr 5, 2022 at 5:47
2

thanks guys for offering answers. I got partial answer from @Luna. Here is solution I came up with.

Problem: After firing n number of transactions in burst, from same address, I wanted api which will help me know how many %transactions have been committed to blockchain.

Solution: While firing transitions in burst, I keep note of startNonce, endingNonce as nonce of first and last transaction I fired. Then I implemented statusCheck() function which gives me % of committed transactions as below.

statusCheck() {
  blockHash = await api.rpc.chain.getBlockHash(); //get # of latest block
  lastCommitedNonce = await api.query.system.account.at(blockHash, stashId); // get latest committed nonce 
  percentTransactionsCompleted = based on startNonce, endingNonce and lastCommitedNonce 
}

My web app is happy to call statusCheck() periodically to know latest committed transaction status.

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.