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

x/smoldot/client.d.ts>Chain

Alternative client for Substrate-based chains.
Go to Latest
interface Chain
import { type Chain } from "https://deno.land/x/smoldot@light-js-deno-v0.6.32/client.d.ts";

Active connection to a blockchain.

Methods

sendJsonRpc(rpc: string): void

Enqueues a JSON-RPC request that the client will process as soon as possible.

The response will be sent back using the callback passed when adding the chain.

See https://www.jsonrpc.org/specification for a specification of the JSON-RPC format. Only version 2 is supported. Be aware that some requests will cause notifications to be sent back using the same callback as the responses.

No response is generated if the request isn't a valid JSON-RPC request or if the request is unreasonably large (64 MiB at the time of writing of this comment). The request is then silently discarded. If, however, the request is a valid JSON-RPC request but that concerns an unknown method, a error response is properly generated.

Two JSON-RPC APIs are supported by smoldot:

databaseContent(maxUtf8BytesSize?: number): Promise<string>

Serializes the important information about the state of the chain so that it can be provided back in the {AddChainOptions.databaseContent} when the chain is recreated.

The content of the string is opaque and shouldn't be decoded.

A parameter can be passed to indicate the maximum length of the returned value (in number of bytes this string would occupy in the UTF-8 encoding). The higher this limit is the more information can be included. This parameter is optional, and not passing any value means "unbounded".

remove(): void

Disconnects from the blockchain.

The JSON-RPC callback will no longer be called.

Trying to use the chain again will lead to an exception being thrown.

If this chain is a relay chain, then all parachains that use it will continue to work. Smoldot automatically keeps alive all relay chains that have an active parachains. There is no need to track parachains and relaychains, or to destroy them in the correct order, as this is handled automatically.