#blockchain #substrate-based #download #browser #towards #smoldot

no-std smoldot-light

Browser bindings to a light client for Substrate-based blockchains

23 releases (breaking)

Uses new Rust 2024

0.19.0 Dec 2, 2025
0.18.0 Oct 20, 2025
0.17.2 Jun 6, 2025
0.17.1 Feb 18, 2025
0.2.0 Sep 7, 2022

#5 in #substrate-based

Download history 65560/week @ 2025-09-23 75171/week @ 2025-09-30 71075/week @ 2025-10-07 56172/week @ 2025-10-14 66792/week @ 2025-10-21 58859/week @ 2025-10-28 76572/week @ 2025-11-04 71634/week @ 2025-11-11 73724/week @ 2025-11-18 78690/week @ 2025-11-25 92974/week @ 2025-12-02 90359/week @ 2025-12-09 75117/week @ 2025-12-16 27612/week @ 2025-12-23 33731/week @ 2025-12-30 73870/week @ 2026-01-06

227,714 downloads per month
Used in 77 crates (2 directly)

GPL-3.0-or-later…

5MB
80K SLoC

Smoldot light client library.

This library provides an easy way to create a light client.

This light client is opinionated towards certain aspects: what it downloads, how much memory and CPU it is willing to consume, etc.

Usage

Initialization

In order to use the light client, call Client::new, passing an implementation of the platform::PlatformRef trait. See the documentation of the platform::PlatformRef trait for more information.

The Client contains two generic parameters:

  • An implementation of the platform::PlatformRef trait.
  • An opaque user data. If you do not use this, you can simply use ().

When the std feature of this library is enabled, the platform::DefaultPlatform struct can be used as an implementation of platform::PlatformRef.

For example:

use smoldot_light::{Client, platform::DefaultPlatform};
let client = Client::new(DefaultPlatform::new(env!("CARGO_PKG_NAME").into(), env!("CARGO_PKG_VERSION").into()));

If the std feature of this library is disabled, then you need to implement the platform::PlatformRef trait manually.

Adding a chain

After the client has been initialized, use Client::add_chain to ask the client to connect to said chain. See the documentation of AddChainConfig for information about what to provide.

Client::add_chain returns a ChainId, which identifies the chain within the Client. A Client can be thought of as a collection of chain connections, each identified by their ChainId, akin to a HashMap<ChainId, ...>.

A chain can be removed at any time using Client::remove_chain. This will cause the client to stop all connections and clean up its internal services. The ChainId is instantly considered as invalid as soon as the method is called.

JSON-RPC requests and responses

Once a chain has been added, one can send JSON-RPC requests using Client::json_rpc_request.

The request parameter of this function must be a JSON-RPC request in its text form. For example: {"id":53,"jsonrpc":"2.0","method":"system_name","params":[]}.

Calling Client::json_rpc_request queues the request in the internals of the client. Later, the client will process it.

Responses can be pulled by calling the AddChainSuccess::json_rpc_responses that is returned after a chain has been added.

Dependencies

~17–35MB
~557K SLoC