3

I've successfully submitted the extrinsic RPC call and got a JSON response

{
    "jsonrpc": "2.0",
    "result": "0x715b0b0d105920a928ad005bd525a68d6b8b60e73afa043174fe0db2f7133db8",
    "id": 1
}

Knowing the transaction hash, how can I know whether the extrinsic got accepted or rejected by the network. Is there a way to see the error code in case of rejection? Thanks

Update

I'm calling a method in a custom pallet. The runtime logic returns a System.ExtrinsicFailed exception with a specific error.

enter image description here

But the submitted extrinsic is still included to the block.

{
    "jsonrpc": "2.0",
    "result": {
        "block": {
            "extrinsics": [
                "0x280402000b74c3add97f01",
                "0xe9018400d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d010a53e10e6c6b4e3f0ec5faf3e4db39e1b70766873ae3462e53c90b1316565e408c7c74dc6bdf4d4274871d44ec27956fd6547b733e6cfacf9b34526251c1ad84006400080040e00b2d48eee975515138552126e2bf8600"
            ],
            "header": {
                "digest": {
                    "logs": [
                        "0x06617572612041ab601000000000",
                        "0x0561757261010126d20fb044834f6f1a9d036403af6ad87bfec598889ddcc174fbaf190c75ce77120ae859cc739b1089850346409868ef229989a91ee08b5d860ed838bc79d68f"
                    ]
                },
                "extrinsicsRoot": "0x35f1510c6c4704691c742a107d2a53e722b65e08d268a369052f728d35b981a1",
                "number": "0x19b4",
                "parentHash": "0x6f589b4e8d8885f59b726689d702e86f55af07af281e4c9377987841c31e7dd4",
                "stateRoot": "0xa9e3f1fc62e82c501289266655eabeb04c3488d67184d683ed27bd4a3e336350"
            }
        },
        "justifications": null
    },
    "id": 1
}

What are logs? Do I understand correctly, that they also can be deserialised? Do they correspond to extrinsic with the same index? Thanks

2 Answers 2

6

I'm facing the same kind of question I think. The problem is that it doesn't really matter if your extrinsic is executed correctly or not, if the transaction submitted is correct (the structure and data), it will be added to the chain.

I haven't find an easier way to determine if the execution was okay or not, but there's this page that I'm sure will help

Polkadot API: https://polkadot.js.org/docs/api/cookbook/blocks#how-do-i-determine-if-an-extrinsic-succeededfailed

Keep in mind that the extrinsic hash might not be unique at some point, so you need to combine block number and extrinsic hash to ensure you are getting the right events.

The following threads are also useful:

How to get extrinsic details by extrinsic hash: https://github.com/polkadot-js/api/issues/2326

Extrinsic hash from Event, How to?: https://github.com/polkadot-js/api/issues/4240

5

The Substrate author_ RPC namespace has 2 submission mechanisms -

  • author_submitExtrinsic - this only returns the hash, doesn't guarantee inclusion
  • author_submitAndWatchExtrinsic - this is a subscription that returns the status of the extrinsic, e.g. Broadcast, InBlock, Finalized, etc.

Once the subscription reaches InBlock(blockHash) or Finalized(blockHash) you can get the DispatchResult from the block to determine the actual runtime execution status.

It may be rejected in the transaction pool already, e.g. a Stale status is an example of this, in that case it won't make it into a block, so it won't get to a Finalized state at all.

If you cannot submit & watch, a more limiting approach would be to watch author_pendingExtrinsics to see if it is unprocessed and check incoming blocks for inclusion. In this case you lose out on any won't-be-included statuses from the transaction pool.

2
  • Thank you, @Jaco. Yeah, the author_submitAndWatchExtrinsic method is available only with web sockets. Unfortunately, I can't use it right now. Using RPC I get the Subscriptions are not available on this transport response. I've updated the question and added more details. Mar 30, 2022 at 7:40
  • The error shown above is from the system events. You need to read the events for the block where it is includes and check ExtrinsicSuccess/Failure to extract the errors for the extrinsic.
    – Barto
    Mar 30, 2022 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.