docs ⦿ dedot 🧑‍💻
TypinkXTelegramGithub
dedot 🧑‍💻
dedot 🧑‍💻
  • Welcome to Dedot
  • Why Dedot?
  • Getting started
    • Installation
    • Connect to network
    • @polkadot/api -> dedot
    • Packages structure
  • Clients & Providers
    • Providers
    • Clients
  • Client API
    • ChainApi
    • Constants
    • Runtime APIs
    • Storage Queries
    • Transactions
    • Events
    • Errors
  • ink! Smart Contracts
    • Introduction
    • Generate Types & APIs
    • Deploy contracts
    • Queries
    • Transactions
    • Events
    • Handle errors
  • CLI
  • Keyring & Signer
  • Runtime upgrades
  • Type system
  • Utilities
    • HexString
    • Uint8Array (U8a)
    • String
    • Hash functions
    • Address
    • BigInt & number
    • Balances
    • Merkleized Metadata
  • Help & FAQ
    • Tutorials
      • Develop ink! dApp using Typink
    • Built with Dedot
    • Forum Posts
    • Telegram
    • Github
    • API Reference
Powered by GitBook
On this page
  • Access ChainApi interfaces
  • Using ChainApi interface

Was this helpful?

Edit on GitHub
  1. Client API

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 ussually has the following structure:

export interface VersionedSubstrateApi<Rv extends RpcVersion>
  rpc: ChainJsonRpcApis<Rv>; // json-rpc methods
  consts: ChainConsts<Rv>; // runtime constants
  query: ChainStorage<Rv>; // on-chain storage queries
  errors: ChainErrors<Rv>; // on-chain errors
  events: ChainEvents<Rv>; // on-chain events
  call: RuntimeApis<Rv>; // runtime apis
  tx: ChainTx<Rv>; // transactions
}

export interface ChainApi {
  legacy: VersionedSubstrateApi<RpcLegacy>; // interface for legacy JSON-RPC
  v2: VersionedSubstrateApi<RpcV2>; // interface for new JSON-RPC
}

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

  • ...

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.

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:

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

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.

Example working with Polkadot Asset Hub:

import { DedotClient, WsProvider } from 'dedot';
import type { PolkadotAssetHubApi } from '@dedot/chaintypes';

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

Last updated 8 months ago

Was this helpful?

Install package @dedot/chaintypes to get access to a . For example:

We're welcome everyone to open a to add your favorite Substrate-based network to the of supported networks in repo.

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 page for more information.

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 .

list of known ChainApi interfaces
PolkadotApi
KusamaApi
PolkadotAssetHubApi
KusamaAssetHubApi
pull request
existing list
@dedot/chaintypes
Runtime upgrades
CLI page