Crate sube

Source
Expand description

Sube is a lightweight Substrate client with multi-backend support that can use a chain’s type information to auto encode/decode data into human-readable formats like JSON.

§Usage

Sube requires one of the metadata versions to be enabled(default: v14). You can change it activating the relevant feature. You will also likely want to activate a backend(default: ws).

[dependencies]
sube = { version = "0.4", default_features = false, features = ["v13", "http"] }

Creating a client is as simple as instantiating a backend and converting it to a Sube instance.

// Create an instance of Sube from any of the available backends
let client: Sube<_> = ws::Backend::new_ws2(CHAIN_URL).await?.into();

// With the client you can:
// - Inspect its metadata
let meta = client.metadata().await?;
let system = meta.pallet_by_name("System").unwrap();
assert_eq!(system.index, 0);

// - Query the chain storage with a path-like syntax
let latest_block: JsonValue = client.query("system/number").await?.into();
assert!(
    latest_block.as_u64().unwrap() > 0,
    "block {} is greater than 0",
    latest_block
);

// - Submit a signed extrinsic
// client.submit(SIGNED_EXTRINSIC).await?;

§Backend features

  • http - Enables a surf based http backend.
  • http-web - Enables surf with its web compatible backend that uses fetch under the hood(target wasm32-unknown-unknown)
  • ws - Enables the websocket backend based on tungstenite
  • wss - Same as ws and activates the TLS functionality of tungstenite

Re-exports§

pub use meta::Metadata;
pub use meta_ext as meta;
pub use codec;

Modules§

http
Surf based backend
meta_ext
ws
Tungstenite based backend

Structs§

Offline
A Dummy backend for offline querying of metadata
RuntimeMetadataPrefixed
Metadata prefixed by a u32 for reserved usage
StorageKey
Represents a key of the blockchain storage in its raw form
Sube
Main interface for interacting with the Substrate based blockchain
Value
A container for SCALE encoded data that can serialize types directly with the help of a type registry and without using an intermediate representation.

Enums§

Error
JsonValue
Represents any valid JSON value.

Traits§

Backend
Generic definition of a blockchain backend

Type Aliases§

Result