npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@polkadot-apps/chain-client

v0.3.8

Published

Multi-chain Polkadot API client with typed access to Asset Hub, Bulletin, and Individuality chains

Readme

@polkadot-apps/chain-client

Multi-chain Polkadot API client with typed access to Asset Hub, Bulletin, and Individuality chains.

Install

pnpm add @polkadot-apps/chain-client

Peer dependency: polkadot-api must be installed in your project.

pnpm add polkadot-api

Host routing: When running inside a Polkadot Desktop/Mobile container, connections are automatically routed through the host via @polkadot-apps/host.

Quick start

import { getChainAPI } from "@polkadot-apps/chain-client";

const api = await getChainAPI("paseo");

// Query Asset Hub
const account = await api.assetHub.query.System.Account.getValue(address);

// Query Bulletin chain
const fee = await api.bulletin.query.TransactionStorage.ByteFee.getValue();

// Use Ink contracts via the contracts SDK
const contract = api.contracts.getContract(descriptor, contractAddress);

Supported environments

getChainAPI accepts an Environment value. Currently only "paseo" is fully configured with all three chains (Asset Hub, Bulletin, Individuality). Calling getChainAPI("polkadot") or getChainAPI("kusama") throws until those environments are live.

| Environment | Asset Hub | Bulletin | Individuality | Status | |-------------|-----------|----------|---------------|--------| | "paseo" | Yes | Yes | Yes | Available | | "polkadot" | -- | -- | -- | Not yet available | | "kusama" | -- | -- | -- | Not yet available |

Connection routing

Connections are established automatically based on the runtime environment:

  • Inside a container (Polkadot Desktop/Mobile): routes through the Host API via @polkadot-apps/host.
  • Outside a container (standalone browser or Node.js): connects directly over WebSocket RPC.

Detect the environment programmatically:

import { isInsideContainer } from "@polkadot-apps/chain-client";

if (isInsideContainer()) {
  console.log("Connections routed through Host API");
}

Chain API structure

The object returned by getChainAPI provides typed access to each chain's runtime, derived from on-chain descriptors. Every property and query method is fully typed -- no manual type assertions needed.

const api = await getChainAPI("paseo");

// api.assetHub  — typed API for Paseo Asset Hub
// api.bulletin   — typed API for Bulletin chain
// api.individuality — typed API for Individuality chain
// api.contracts  — Ink SDK instance bound to Asset Hub
// api.destroy()  — close all connections for this environment

Contracts

The contracts property is an Ink SDK instance (createInkSdk) pre-configured for the environment's Asset Hub. Use it to interact with ink! smart contracts.

const api = await getChainAPI("paseo");

const contract = api.contracts.getContract(descriptor, contractAddress);
const result = await contract.query.myMethod(args);

Bundle size

Descriptors are lazy-loaded per environment. Calling getChainAPI("paseo") only bundles metadata for Paseo Asset Hub, Bulletin, and Individuality -- not all five supported chains. Unused environments (e.g., Polkadot, Kusama) are excluded from the bundle via dynamic imports.

Raw client access

For advanced use cases, access the underlying PolkadotClient directly or check connection status.

import { getClient, isConnected } from "@polkadot-apps/chain-client";
import { paseo_asset_hub } from "@polkadot-apps/descriptors/paseo-asset-hub";

const client = getClient(paseo_asset_hub);
const connected = isConnected(paseo_asset_hub); // boolean, synchronous

Cleanup

Destroy connections when they are no longer needed. You can destroy a single environment or all environments at once.

import { getChainAPI, destroyAll } from "@polkadot-apps/chain-client";

const api = await getChainAPI("paseo");

// Destroy one environment
api.destroy();

// Destroy all environments
destroyAll();

API

getChainAPI<E extends Environment>(env: E): Promise<ChainAPI<E>>

Return the typed chain API for a given environment. Results are cached -- calling getChainAPI("paseo") twice returns the same instance.

| Parameter | Type | Description | |-----------|------|-------------| | env | Environment | "polkadot", "kusama", or "paseo". |

Returns: Promise<ChainAPI<E>> with typed assetHub, bulletin, individuality, contracts, and destroy().

Throws when the requested environment is not yet available.

destroyAll(): void

Destroy all cached chain API instances and close their connections.

getClient(descriptor): PolkadotClient

Return the raw PolkadotClient for a connected chain identified by its descriptor.

| Parameter | Type | Description | |-----------|------|-------------| | descriptor | ChainDefinition | A chain descriptor from @polkadot-apps/descriptors. |

isConnected(descriptor): boolean

Check whether a chain is currently connected. Synchronous.

| Parameter | Type | Description | |-----------|------|-------------| | descriptor | ChainDefinition | A chain descriptor from @polkadot-apps/descriptors. |

isInsideContainer(): boolean

Synchronous check for whether the app is running inside a Polkadot Desktop/Mobile container. Re-exported from @polkadot-apps/host.

Types

type Environment = "polkadot" | "kusama" | "paseo";

type ChainAPI<E extends Environment> = {
  assetHub: TypedApi;        // typed from descriptors for the given environment
  bulletin: TypedApi;        // typed from the bulletin descriptor
  individuality: TypedApi;   // typed from the individuality descriptor
  contracts: InkSdk;         // Ink SDK bound to Asset Hub
  destroy: () => void;
};

type ConnectionMode = "rpc" | "lightclient";

interface ChainMeta {
  rpcs?: readonly string[];
  relayChainSpec?: string;
  paraChainSpec?: string;
  mode?: ConnectionMode;
}

License

Apache-2.0