# ChainApi

`ChainApi` interface is a concept that allows Dedot to enable Types & APIs suggestions for any Substrated-based blockchains. Each Substrate-based blockchain has its own `ChainApi` interface that exposes all of its Types & APIs to interact with the node & runtime.

A `ChainApi` interface has the following structure:

```typescript
export interface ChainApi {
  rpc: ChainJsonRpcApis; // json-rpc methods
  consts: ChainConsts; // runtime constants
  query: ChainStorage; // on-chain storage queries
  errors: ChainErrors; // on-chain errors
  events: ChainEvents; // on-chain events
  call: RuntimeApis; // runtime apis
  tx: ChainTx<ChainKnownTypes>; // transactions
  
  types: ChainKnownTypes; // known chain types from the runtime (Address, Signature, AssetId ...)
}
```

### Access `ChainApi` interfaces

Dedot offers 2 different ways to access `ChainApi` interfaces for different Substrate-based blockchains.

#### Known `ChainApi` interfaces defined in `@dedot/chaintypes` package

Install package `@dedot/chaintypes` to get access to a [list of known `ChainApi` interfaces](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/index.ts). For example:

* [`PolkadotApi`](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/polkadot/index.d.ts)
* [`KusamaApi`](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/kusama/index.d.ts)
* [`PolkadotAssetHubApi`](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/polkadot-asset-hub/index.d.ts)
* [`KusamaAssetHubApi`](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/kusama-asset-hub/index.d.ts)
* ...

{% hint style="info" %}
We're welcome everyone to open a [pull request](https://github.com/dedotdev/chaintypes/pulls) to add your favorite Substrate-based network to the [existing list](https://github.com/dedotdev/chaintypes/blob/main/scripts/networks.ts) of supported networks in[`@dedot/chaintypes`](https://github.com/dedotdev/chaintypes) repo.
{% endhint %}

{% hint style="info" %}
There is a job running twice a day to check for any runtime upgrades in the existing supported networks list and regenerate the `ChainApi` interface (Types & APIs) accordingly for these changes.&#x20;

It's important to keep up with changes from the network that you're working with and prepare for any breaking upgrades coming up. Please refer to the [Runtime upgrades](/runtime-upgrades.md) page for more information.
{% endhint %}

#### Generate `ChainApi` interface using Dedot's CLI

You can also generate `ChainApi` interface for any Substrate-based blockchains using `dedot`' CLI.

Generate `ChainApi` interface for a local substrate-based blockchains running on `ws://127.0.0.1:9944`:

```sh
npx dedot chaintypes -w ws://127.0.0.1:9944
```

You can also generate `ChainApi` interface using a raw metadata file (.scale) or runtime wasm file (.wasm). More information about this can be found in the [CLI page](https://docs.dedot.dev/cli#dedot-chaintypes).

### Using `ChainApi` interface

`ChainApi` interface is the generic parameter for Dedot's clients, so when intialize a Dedot client, make sure to pick the right `ChainApi` interface of the chain you're working with to enable Types & APIs suggestions for that particular chains.

<figure><img src="/files/KzMlIpCMlX4aBfQ67pym" alt=""><figcaption></figcaption></figure>

Example working with Polkadot Asset Hub:

<pre class="language-typescript"><code class="lang-typescript"><strong>import { DedotClient, WsProvider } from 'dedot';
</strong>import type { PolkadotAssetHubApi } from '@dedot/chaintypes';

// Initialize providers &#x26; clients
const provider = new WsProvider('wss://polkadot-asset-hub-rpc.polkadot.io');
const client = await DedotClient.new&#x3C;PolkadotAssetHubApi>(provider);
</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dedot.dev/client-api/chainapi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
