Skip to content

Commit

Permalink
feat: add InvalidTxError explanation (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Josep M Sobrepere <[email protected]>
  • Loading branch information
carlosala and josepot authored Jul 25, 2024
1 parent 9d7dcf9 commit 2b469dc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/pages/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChainSpecData>

Expand Down Expand Up @@ -102,7 +102,7 @@ interface PolkadotClient {
* @param descriptors Pass descriptors from `@polkadot-api/descriptors`
* generated by `papi` CLI.
*/
getTypedApi: <D extends Descriptors>(descriptors: D) => TypedApi<D>
getTypedApi: <D extends ChainDefinition>(descriptors: D) => TypedApi<D>

/**
* This will `unfollow` the provider, disconnect and error every subscription.
Expand Down
26 changes: 26 additions & 0 deletions docs/pages/typed/tx.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof myChain> = 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:
Expand Down

0 comments on commit 2b469dc

Please sign in to comment.