Niklas Adolfsson abd7a4145b introduce jsonrpsee client abstraction + kill HTTP support. (#341)
* PoC async rpc client

* add client example should be removed from this repo

* fmt

* cargo fmt

* subxt client tests

* cargo fmt

* fix some nits

* try nightly for all CI jobs

* need wasm also for CI

* wasm for nightly run too

* client: add missing features

* update jsonrpsee

* hacky update jsonrpsee

* use jsonrpsee crates.io release

* ci: pin nightly 2021-12-15

* pin nightly to 2021-12-15

* fix build

* fmt

* compile please

* rewrite me

* fixes

* fixes

* pre-generate metadata

* fix nit

* get rid of needless deps

* remove embedded client

* Update Cargo.toml

* Update subxt/Cargo.toml

* Update subxt/Cargo.toml

* Update subxt/src/client.rs

* Update subxt/src/rpc.rs

* Update test-runtime/build.rs

* cargo fmt

Co-authored-by: James Wilson <james@jsdw.me>
2022-02-04 10:35:59 +00:00
2022-02-01 10:48:41 +00:00
2022-02-01 10:48:41 +00:00
2022-01-05 10:26:03 +00:00

subxt · build Latest Version Documentation

A library to submit extrinsics to a substrate node via RPC.

⚠️ Health Warning ⚠️ considered alpha after recent changes, API still subject to change

See https://github.com/paritytech/subxt/issues/309 for an overview of outstanding issues.

Usage

Take a look in the examples folder for various subxt usage examples.

Downloading metadata from a Substrate node

Use the subxt-cli tool to download the metadata for your target runtime from a node.

  1. Install:
cargo install subxt-cli
  1. Save the encoded metadata to a file:
subxt metadata -f bytes > metadata.scale

This defaults to querying the metadata of a locally running node on the default http://localhost:9933/. If querying a different node then the metadata command accepts a --url argument.

Generating the runtime API from the downloaded metadata

Declare a module and decorate it with the subxt attribute which points at the downloaded metadata for the target runtime:

#[subxt::subxt(runtime_metadata_path = "metadata.scale")]
pub mod node_runtime { }

Important: runtime_metadata_path resolves to a path relative to the directory where your crate's Cargo.toml resides (CARGO_MANIFEST_DIR), not relative to the source file.

Initializing the API client

API is still a work in progress. See examples for the current usage.

Querying Storage

API is still a work in progress. See tests for the current usage.

Submitting Extrinsics

API is still a work in progress. See examples for the current usage.

Integration Testing

Most tests require a running substrate node to communicate with. This is done by spawning an instance of the substrate node per test. It requires an executable binary substrate at polkadot-v0.9.10 on your path.

This can be installed from source via cargo:

cargo install --git https://github.com/paritytech/substrate node-cli --tag=polkadot-v0.9.10 --force

Real world usage

Please add your project to this list via a PR.

  • cargo-contract CLI for interacting with Wasm smart contracts.
  • xcm-cli CLI for submitting XCM messages.
  • phala-pherry The relayer between Phala blockchain and the off-chain Secure workers.
  • crunch CLI to claim staking rewards in batch every Era or X hours for substrate-based chains.
  • interbtc-clients Client implementations for the interBTC parachain; notably the Vault / Relayer and Oracle.

Alternatives

substrate-api-client provides similar functionality.

License

The entire code within this repository is licensed under the GPLv3. Please contact us if you have questions about the licensing of our products.
S
Description
No description provided
Readme 529 MiB
Languages
Rust 99.8%
Shell 0.2%