1

I'd like to get if the extrinsic completed without any extrinsic errors and get the errors if any. result.isError returns false when there's an error.

Could this be because I return DispatchResult instead of DispatchResultWithPostInfo in my pallet?

As this GitHub issue comment suggests, it can be done by getting the block details. But, I'm looking for a more simplified answer.

myTx.signAndSend(pair, (result) => {
    console.log(`Current status is ${result.status}`);

    console.log('has error', result.isError); // false

    if (result.isError) {
        console.log('dispatchError', result.dispatchError?.toHuman())
        console.log('internalError', result.internalError)
    }

    if (result.status.isInBlock) {
        console.log(`Transaction included at blockHash ${result.status.asInBlock}`);
    } else if (result.status.isFinalized) {
        console.log(`Transaction finalized at blockHash ${result.status.asFinalized}`);
    }
});

1 Answer 1

1

If there is a dispatchError then the transaction failed.

Have you tried something like this:

myTx.signAndSend(sender, ({ status, events, dispatchError }) => {
    // status would still be set, but in the case of error we can shortcut
    // to just check it (so an error would indicate InBlock or Finalized)
    if (dispatchError) {
      if (dispatchError.isModule) {
        // for module errors, we have the section indexed, lookup
        const decoded = api.registry.findMetaError(dispatchError.asModule);
        const { docs, name, section } = decoded;

        console.log(`${section}.${name}: ${docs.join(' ')}`);
      } else {
        // Other, CannotLookup, BadOrigin, no extra info
        console.log(dispatchError.toString());
      }
    }
  });

Reference: https://polkadot.js.org/docs/api/cookbook/tx#how-do-i-get-the-decoded-enum-for-an-extrinsicfailed-event

1
  • What is docs used for in RegistryError?
    – Burak
    Mar 4, 2022 at 0:25

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.