How can i subscribe to the new pending transactions of polkadot by using substrate interface python
-
I don't think its possible to subscribe on it, but you can use polling. What is your use-case?– Oliver Tale-YazdiSep 8, 2022 at 18:17
-
My usecase is that if someone has deposited some amount of dots how would I come to know that from a particular account an amount of dots has deposited in my account?– Shahbaz AliSep 12, 2022 at 5:31
-
1By subscribing to events. This should never be done through pending transactions, since they can be invalid or removed by a re-org.– Oliver Tale-YazdiSep 12, 2022 at 13:06
2 Answers
I think what you mean is the author_pendingExtrinsics
RPC call, so that would be something like:
result = substrate.rpc_request("author_pendingExtrinsics", [])
Another angle, I think it's difference in terminology here. What you probably mean by coming from Ethereum is that pending transactions are transactions that are not yet 'finalized` in Substrate.
Finalized means it can never ever change. In a POW chain you work with confirmations, which gives you some kind certainty, in Substrate you have finality and give you absolute certainty.
This is different than the 'pending extrinsics' in Substrate, which means extrinsics in the tx pool, not yet including in a block.
What you probably want to know is which extrinsics are not yet finalized. So you just retrieve the finalized block_number:
result = substrate.get_block_header(finalized_only=True)
finalized_block_number = result['header']['number']
And any extrinsic in block height higher than that is a pending (unfinalized) extrinsic.
-
Arjan you're almost right about the concept of pending transactions.My usecase is that if someone has deposited some amount of dots how would I come to know that from a particular account an amount of dots has deposited in my account? Sep 12, 2022 at 5:25