Quickly get started with experimenting with Subxt, a Rust library for interacting with Polkadot SDK-based blockchains.
Getting started should be simple - simply clone this repository, cargo build, and you're off to the races.
-
Be sure you have Rust and its associated tooling installed.
-
Install the
subxt-cli:cargo install subxt-cli
cargo build # This will install and build everythingsrc/
├── main.rs # Main application entry point with demo workflow
├── config.rs # Configuration constants and metadata generation
└── remark.rs # Transaction and query functionality modules
metadata/
└── paseo.scale # Paseo runtime metadata
This boilerplate demonstrates several key Subxt functionalities:
- Runtime Information Query: Fetches the last runtime upgrade information from Paseo
- Account Information: Retrieves account details for a given address
- Transaction Signing & Submission: Creates and submits a remark transaction with event monitoring
To run the complete demo, you can simply use cargo:
cargo runThe demo will:
- Connect to the Paseo test network
- Query runtime upgrade information
- Fetch Alice's account information
- Create a signer from a mnemonic
- Submit a remark transaction and wait for the event
If you have a custom-built chain, such as one built with the "Zero to Hero" guide for building custom blockchains using the Polkadot SDK, here's how you can accommodate the boilerplate to use that instead of a production network.
- Make sure you have
subxt-cliinstalled (see: Prerequisites), and run the following for your network (localhostor deployed or a url works):
subxt metadata -f bytes --url ws://localhost:9944 > ./metadata/custom.scale- In your
src/config.rsfile, change the metadata path and module name:
// Change this:
#[subxt::subxt(runtime_metadata_path = "./metadata/paseo.scale")]
pub mod paseo {}
// To this:
#[subxt::subxt(runtime_metadata_path = "./metadata/custom.scale")]
pub mod custom {}
// Also update the RPC URL:
pub const RPC_URL: &str = "ws://localhost:9944";-
Update your
src/remark.rsfile to use the custom module instead ofpaseo:- Change all references from
paseo::tocustom:: - If using a different config type, change
PolkadotConfigtoSubstrateConfigor your custom config
- Change all references from
-
In
src/main.rs, update the import to use your custom module:
use crate::config::{ SubXtResult, custom };If you need to create a custom configuration that isn't the "generic" Substrate one, follow this guide.