diff --git a/docs/pages/client.md b/docs/pages/client.md index aff8b170..30df483f 100644 --- a/docs/pages/client.md +++ b/docs/pages/client.md @@ -5,8 +5,8 @@ ```ts interface PolkadotClient { /** - * Retrieve the ChainSpecData as it comes from the - * [JSON-RPC spec](https://paritytech.github.io/json-rpc-interface-spec/api/chainSpec.html) + * Retrieve the ChainSpecData as it comes from the [JSON-RPC + * spec](https://paritytech.github.io/json-rpc-interface-spec/api/chainSpec.html) */ getChainSpecData: () => Promise @@ -102,7 +102,7 @@ interface PolkadotClient { * @param descriptors Pass descriptors from `@polkadot-api/descriptors` * generated by `papi` CLI. */ - getTypedApi: (descriptors: D) => TypedApi + getTypedApi: (descriptors: D) => TypedApi /** * This will `unfollow` the provider, disconnect and error every subscription. diff --git a/docs/pages/typed/tx.md b/docs/pages/typed/tx.md index ad1a6066..c5c399ff 100644 --- a/docs/pages/typed/tx.md +++ b/docs/pages/typed/tx.md @@ -163,6 +163,32 @@ type TxFinalized = { You get the `txHash`; the bunch of `events` that this extrinsic emitted (see [this section]("/typed/events") to see what to do with them); `ok` which simply tells if the extrinsic was successful (i.e. event `System.ExtrinsicSuccess` is found) and the `block` information where the tx is found. +### `InvalidError` + +When a transaction is deemed as invalid (due to, for example, wrong nonce, expired mortality, not enough balance to pay the fees, etc) we provide a strongly typed error. It can be used as follows: + +```ts +import { InvalidTxError, TransactionValidityError } from "polkadot-api" +import { myChain } from "@polkadot-api/descriptors" + +tx.signAndSubmit(signer) + .then(() => "tx went well") + .catch((err) => { + if (err instanceof InvalidTxError) { + const typedErr: TransactionValidityError = err.error + console.log(typedErr) + } + }) +``` + +This `typedErr` will be, then, strongly typed as any other type coming from PAPI. Its content might differ per chain, but it enables the developer to get the information required and act accordingly. + +:::info +This error will only be available for chains with Runtime Metadata `v15` or greater. + +In case you are using the whitelist feature of the codegen, remember to add `"api.TaggedTransactionQueue.validate_transaction"` to the list of whitelisted interactions. +::: + ## `signSubmitAndWatch` `signSubmitAndWatch` is the Observable-based version of `signAndSubmit`. The function returns an Observable and will emit a bunch of events giving information about the status of transaction in the chain, until it'll be eventually finalized. Let's see its interface: