0

Context: We are using GSRPC for interacting with a Polkadot Node. We are sending transactions using SubmitAndWatchExtrinsic.

Question: How can I detect if the transaction failed?


Note: I am aware that the ExtrinsicStatusSubscription reports about the status of an extrinsic. However, it does not seem to report whether the transaction failed during execution.

1 Answer 1

1

This is a bit confusing indeed, since extrinsics in Substrate don't "fail" in the error case.
Extrinsics will emit an ExtrinsicFailed event when returning an error, but still execute fine.
This stands in contrast to Ethereum, where a transaction reverts and does not execute in the error case.

In general you have to wait for the extrinsic to be included in a block.
Then read the events of your extrinsic from that block. There should either be a ExtrinsicSuccess or ExtrinsicFailed event.
GSRPC has some rough edges, I don't think it exposes everything that is necessary for this approach.

Another "hacky" way of doing it; Wait for the event that would be emitted in the success case with a timeout.
If it times out, you know that it did not work. In the other case it could also be that someone else send a successful extrinsic, whos event you now see.

1
  • Hi Oli, thanks for the reply. I've seen that I can subscribe to EventSystemExtrinsicFailed events. However, I don't see a way how to identify which transaction / extrinsic they belong to.
    – mpn
    Jul 18, 2022 at 14:24

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.