31 releases (breaking)

0.37.0 May 28, 2024
0.35.3 Apr 11, 2024
0.35.0 Mar 21, 2024
0.33.0 Dec 7, 2023
0.2.0 Nov 15, 2021

#435 in Magic Beans

Download history 6232/week @ 2024-03-03 5842/week @ 2024-03-10 6776/week @ 2024-03-17 5887/week @ 2024-03-24 9756/week @ 2024-03-31 7925/week @ 2024-04-07 5840/week @ 2024-04-14 6292/week @ 2024-04-21 5561/week @ 2024-04-28 5781/week @ 2024-05-05 5937/week @ 2024-05-12 4985/week @ 2024-05-19 5346/week @ 2024-05-26 6599/week @ 2024-06-02 5101/week @ 2024-06-09 4865/week @ 2024-06-16

22,307 downloads per month
Used in 57 crates (2 directly)

Apache-2.0 OR GPL-3.0

240KB
5K SLoC

subxt · build Latest Version Documentation

Subxt is a library for interacting with Substrate based nodes in Rust and WebAssembly. It can:

  • Submit Extrinsics (this is where the name comes from).
  • Subscribe to blocks, reading the extrinsics and associated events from them.
  • Read and iterate over storage values.
  • Read constants and custom values from the metadata.
  • Call runtime APIs, returning the results.
  • Do all of the above via a safe, statically types interface or via a dynamic one when you need the flexibility.
  • Compile to WASM and run entirely in the browser.
  • Do a bunch of things in a #[no_std] environment via the subxt-core crate.
  • Use a built-in light client (smoldot) to interact with chains.

Usage

Take a look in the examples folder or the examples folder for various smaller or larger subxt usage examples, or read the guide to learn more.

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.

Subxt Documentation

For more details regarding utilizing subxt, please visit the documentation.

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 up-to-date substrate executable on your path.

This can be installed from source via cargo:

cargo install --git https://github.com/paritytech/polkadot-sdk staging-node-cli --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.
  • tidext Tidechain client with Stronghold signer.
  • staking-miner-v2 Submit NPos election solutions and get rewards.
  • polkadot-introspector Tools for monitoring Polkadot nodes.
  • ink! Smart contract language that uses subxt for allowing developers to conduct End-to-End testing of their contracts.
  • Chainflip A decentralised exchange for native cross-chain swaps.

Alternatives

substrate-api-client provides similar functionality.

License

The entire code within this repository is dual licensed under the GPL-3.0 or Apache-2.0 licenses. See the LICENSE file for more details.

Please contact us if you have questions about the licensing of our products.


lib.rs:

Generate a type safe Subxt interface for a Substrate runtime from its metadata. This is used by the #[subxt] macro and subxt codegen CLI command, but can also be used directly if preferable.

Dependencies

~6–18MB
~232K SLoC