Skip to main content

Connecting with subxt

subxt is a Rust library for interacting with Polkadot and Substrate-based chains, maintained by Parity Technologies.

Installation

Add subxt to your Cargo.toml:

[dependencies]
subxt = "0.50"
tokio = { version = "1", features = ["full"] }

Generating the metadata

subxt metadata --url wss://asset-hub.polkadot.rpc.deserve.network > metadata.scale

Connecting to the geo-steered endpoint

use subxt::{OnlineClient, PolkadotConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api = OnlineClient::<PolkadotConfig>::from_url(
"wss://asset-hub.polkadot.rpc.deserve.network"
).await?;

println!("Connected. Genesis hash: {:?}", api.genesis_hash());
Ok(())
}

Connecting to a regional endpoint

use subxt::{OnlineClient, PolkadotConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// replace with your preferred regional endpoint
let api = OnlineClient::<PolkadotConfig>::from_url(
"wss://london.asset-hub.polkadot.rpc.deserve.network"
).await?;

println!("Connected. Genesis hash: {:?}", api.genesis_hash());
Ok(())
}

Available endpoints

NetworkEndpoints
Polkadot Asset HubLink
Polkadot CoretimeLink