#![allow(missing_docs)]
use subxt_rpcs::{RpcConfig, client::RpcClient, methods::LegacyRpcMethods};
pub enum MyCustomConfig {}
impl RpcConfig for MyCustomConfig {
type Header = subxt::config::substrate::SubstrateHeader<subxt::config::substrate::H256>;
type Hash = subxt::config::substrate::H256;
type AccountId = subxt::config::substrate::AccountId32;
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let rpc_client = RpcClient::from_url("wss://rpc.polkadot.io").await?;
let rpc = LegacyRpcMethods::<MyCustomConfig>::new(rpc_client);
let chain_name = rpc.system_chain().await?;
println!("Connected to chain: {}", chain_name);
let finalized_hash = rpc.chain_get_finalized_head().await?;
println!("Latest finalized block: {:?}", finalized_hash);
let header = rpc.chain_get_header(Some(finalized_hash)).await?;
if let Some(header) = header {
println!("Block number: {}", header.number);
println!("Parent hash: {:?}", header.parent_hash);
}
println!("\nThis example demonstrates that you can define your own RpcConfig");
println!("to match the types used by your specific blockchain.");
println!("However, for most Substrate chains, using RpcConfigFor<PolkadotConfig> is simpler!");
Ok(())
}