mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-22 05:37:58 +00:00
ed25a3ac26
* Remove codec::Encode and codec::Decode from generated APIs by default * clippy fixes * clippy * More fixes, and CompactAs only if Encode/Decode * revert println in example * fix lightclient test * fix docs * Fix another rust doc comment * Fix failing storage test * Remove now-unnecessary test * clippy * clippy * Remove pointless clone
32 lines
1.1 KiB
Rust
32 lines
1.1 KiB
Rust
#![allow(missing_docs)]
|
|
use subxt::{OnlineClient, PolkadotConfig};
|
|
use subxt_signer::sr25519::dev;
|
|
|
|
// Generate an interface that we can use from the node's metadata.
|
|
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
|
|
pub mod polkadot {}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
// Create a new API client, configured to talk to Polkadot nodes.
|
|
let api = OnlineClient::<PolkadotConfig>::new().await?;
|
|
|
|
// Build a storage query to access account information.
|
|
let account = dev::alice().public_key().into();
|
|
let storage_query = polkadot::storage().system().account(account);
|
|
|
|
// Use that query to `fetch` a result. This returns an `Option<_>`, which will be
|
|
// `None` if no value exists at the given address. You can also use `fetch_default`
|
|
// where applicable, which will return the default value if none exists.
|
|
let result = api
|
|
.storage()
|
|
.at_latest()
|
|
.await?
|
|
.fetch(&storage_query)
|
|
.await?;
|
|
|
|
let v = result.unwrap().data.free;
|
|
println!("Alice: {v}");
|
|
Ok(())
|
|
}
|