Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/smoldot2/public-types.d.ts>Client

Lightweight client for Substrate-based chains, such as Polkadot and Kusama.
Latest
interface Client
import { type Client } from "https://deno.land/x/smoldot2@light-js-deno-v2.0.31/public-types.d.ts";

Client with zero or more active connections to blockchains.

Methods

addChain(options: AddChainOptions): Promise<Chain>

Connects to a chain.

After you've called this function, the client will verify whether the chain specification is valid. Once this is done, the Promise returned by this function will yield a Chain that can be used to interact with that chain. Only after the Promise has yielded will the client actually start establishing networking connections to the chain.

The Promise throws an exception if the chain specification isn't valid, or if the chain specification concerns a parachain but no corresponding relay chain can be found.

Smoldot will automatically de-duplicate chains if multiple identical chains are added, in order to save resources. In other words, it is not a problem to call addChain multiple times with the same chain specifications and obtain multiple Chain objects. When the same client is used for multiple different purposes, you are in fact strongly encouraged to trust smoldot and not attempt to de-duplicate chains yourself, as determining whether two chains are identical is complicated and might have security implications.

Smoldot tries to distribute CPU resources equally between all active Chain objects of the same client.

terminate(): Promise<void>

Terminates the client.

This implicitly calls Chain.remove on all the chains associated with this client, then shuts down the client itself.

Afterwards, trying to use the client or any of its chains again will lead to an exception being thrown.