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

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

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

Configuration of a blockchain.

Properties

chainSpec: string

JSON-encoded specification of the chain.

The specification of the chain can be generated from a Substrate node by calling <client> build-spec --raw > spec.json. Only "raw" chain specifications are supported by smoldot at the moment.

If the chain specification contains a relayChain field, then smoldot will try to match the value in relayChain with the value in id of the chains in AddChainOptions.potentialRelayChains.

optional
databaseContent: string

Content of the database of this chain.

The content of the database can be obtained by using the chainHead_unstable_finalizedDatabase JSON-RPC function. This undocumented JSON-RPC function accepts one parameter of type number indicating an upper limit to the size of the database. The content of the database is always a UTF-8 string whose content is at the discretion of the smoldot implementation.

Smoldot reserves the right to change its database format, making previous databases incompatible. For this reason, no error is generated if the content of the database is invalid and/or can't be decoded.

Providing a database can considerably improve the time it takes for smoldot to be fully synchronized with a chain by reducing the amount of data that it has to download. Furthermore, the database also contains a list of nodes that smoldot can use in order to reduce the load that is being put on the bootnodes.

Important: please note that using a malicious database content can lead to a security vulnerability. This database content is considered by smoldot as trusted input. It is the responsibility of the API user to make sure that the value passed in this field comes from the same source of trust as the chain specification that was used when retrieving this database content. In other words, if you load this database content for example from the disk or from the browser's local storage, be absolutely certain that no malicious program has modified the content of that file or local storage.

optional
potentialRelayChains: Chain[]

If chainSpec concerns a parachain, contains the list of chains whose id smoldot will try to match with the parachain's relayChain. Defaults to [].

Must contain exactly the Chain objects that were returned by previous calls to addChain. The library uses a WeakMap in its implementation in order to identify chains.

Explanation and usage

The primary way smoldot determines which relay chain is associated to a parachain is by inspecting the chain specification of that parachain (i.e. the chainSpec field).

This poses a problem in situations where the same client is shared between multiple different applications: multiple applications could add mutiple different chains with the same id, creating an ambiguity, or an application could register malicious chains with small variations of a popular chain's id and try to benefit from a typo in a legitimate application's relayChain.

These problems can be solved by using this parameter to segregate multiple different uses of the same client. To use it, pass the list of all chains that the same application has previously added to the client. By doing so, you are guaranteed that the chains of multiple different applications can't interact in any way (good or bad), while still benefiting from the de-duplication of resources that smoldot performs in addChain.

When multiple different parachains use the same relay chain, it is important to be sure that they are indeed using the same relay chain, and not accidentally using different ones. For this reason, this parameter is a list of potential relay chains in which only one chain should match, rather than a single Chain corresponding to the relay chain.

optional
disableJsonRpc: boolean

Disables the JSON-RPC system of the chain.

This option can be used in order to save up some resources.

It will be illegal to call Chain.sendJsonRpc and Chain.nextJsonRpcResponse on this chain.

optional
jsonRpcMaxPendingRequests: number

Maximum number of JSON-RPC requests that haven't been answered yet. Any further request will be rejected.

This field is ignored if AddChainOptions.disableJsonRpc is true.

A zero, negative or NaN value is invalid and will generate a AddChainError.

If this value is not set, it means that there is no maximum.

optional
jsonRpcMaxSubscriptions: number

Maximum number of active JSON-RPC subscriptions. Any further subscription will be rejected.

This field is ignored if AddChainOptions.disableJsonRpc is true.

A negative or NaN value is invalid and will generate a AddChainError.

If this value is not set, it means that there is no maximum.