Skip to content

polkadot-developers/polkadot-subxt-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers


Subxt Rust Boilerplate

Quickly get started with experimenting with Subxt, a Rust library for interacting with Polkadot SDK-based blockchains.

Getting Started

Getting started should be simple - simply clone this repository, cargo build, and you're off to the races.

Prerequisites

  • Be sure you have Rust and its associated tooling installed.

  • Install the subxt-cli:

    cargo install subxt-cli

Installation

cargo build # This will install and build everything

Project Structure

src/
├── 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

Usage

This boilerplate demonstrates several key Subxt functionalities:

  1. Runtime Information Query: Fetches the last runtime upgrade information from Paseo
  2. Account Information: Retrieves account details for a given address
  3. Transaction Signing & Submission: Creates and submits a remark transaction with event monitoring

To run the complete demo, you can simply use cargo:

cargo run

The 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

Adding a custom chain

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.

  1. Make sure you have subxt-cli installed (see: Prerequisites), and run the following for your network (localhost or deployed or a url works):
subxt metadata -f bytes --url ws://localhost:9944 > ./metadata/custom.scale
  1. In your src/config.rs file, 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";
  1. Update your src/remark.rs file to use the custom module instead of paseo:

    • Change all references from paseo:: to custom::
    • If using a different config type, change PolkadotConfig to SubstrateConfig or your custom config
  2. 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages