1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2019-2025 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
//! # Light Client
//!
//! The light client based interface uses _Smoldot_ to connect to a _chain_, rather than an
//! individual node. This means that you don't have to trust a specific node when interacting with
//! some chain.
//!
//! This feature is currently unstable. Use the `unstable-light-client` feature flag to enable it.
//! To use this in WASM environments, enable the `web` feature flag and disable the "native" one.
//!
//! To connect to a blockchain network, the Light Client requires a trusted sync state of the
//! network, known as a _chain spec_. One way to obtain this is by making a `sync_state_genSyncSpec`
//! RPC call to a trusted node belonging to the chain that you wish to interact with.
//!
//! Subxt exposes a utility method to obtain the chain spec:
//! [`crate::utils::fetch_chainspec_from_rpc_node()`]. Alternately, you can manually make an RPC
//! call to `sync_state_genSyncSpec` like do (assuming a node running locally on port 9933):
//!
//! ```bash
//! curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "sync_state_genSyncSpec", "params":[true]}' http://localhost:9933/ | jq .result > chain_spec.json
//! ```
//!
//! ## Examples
//!
//! ### Basic Example
//!
//! This basic example uses some already-known chain specs to connect to a relay chain and parachain
//! and stream information about their finalized blocks:
//!
//! ```rust,ignore
//! ```
//!
//! ### Connecting to a local node
//!
//! This example connects to a local chain and submits a transaction. To run this, you first need
//! to have a local pezkuwi node running using the following command:
//! ```text
//! pezkuwi --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001
//! ```
//!
//! Then, the following code will download a chain spec from this local node, alter the bootnodes
//! to point only to the local node, and then submit a transaction through it.
//! ```rust,ignore
//! ```
//!