Skip to content

Commit 580721b

Browse files
committed
feat(tx): add DispatchError section
1 parent 6a49ad3 commit 580721b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/pages/typed/tx.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,33 @@ This error will only be available for chains with Runtime Metadata `v15` or grea
333333

334334
In case you are using the whitelist feature of the codegen, remember to add `"api.TaggedTransactionQueue.validate_transaction"` to the list of whitelisted interactions.
335335
:::
336+
337+
### Failed extrinsic
338+
339+
In Polkadot, a transaction can be valid (and therefore not to throw the `InvalidError`) but the inner extrinsic fail. In this case, the event `ExtrinsicFailed` gives all the information required to understand why it failed. We also expose a `dispatchError` field that helps to guess why it failed. Better a picture than a thousand words:
340+
341+
```ts
342+
// `Chain` will change depending on the name you gave the chain
343+
// in the codegen
344+
import { ChainDispatchError } from "@polkadot-api/descriptors"
345+
tx.signSubmitAndWatch(signer).subscribe((ev) => {
346+
if (
347+
ev.type === "finalized" ||
348+
(ev.type === "txBestBlocksState" && ev.found)
349+
) {
350+
// here we are sure that the transaction is in a block (whether finalized or bestBlock)
351+
// with `ok` we know the extrinsic failed
352+
if (!ev.ok) {
353+
const err: ChainDispatchError = ev.dispatchError
354+
// you will have a strongly typed object that you can keep narrowing down
355+
// to find the root of the issue
356+
if (err.type === "Module" && err.value.type === "Balances")
357+
"keep checking..."
358+
}
359+
}
360+
})
361+
```
362+
363+
:::info
364+
In case you are using the whitelist feature of the codegen, remember to add `"event.System.ExtrinsicFailed"` to the list of whitelisted interactions.
365+
:::

0 commit comments

Comments
 (0)