diff --git a/examples/examples/chainhead_subscription.rs b/examples/examples/chainhead_subscription.rs index d7cf02d9dd..37a0bc458d 100644 --- a/examples/examples/chainhead_subscription.rs +++ b/examples/examples/chainhead_subscription.rs @@ -15,6 +15,8 @@ use subxt::{ PolkadotConfig, }; +use futures::StreamExt; + #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")] pub mod polkadot {} @@ -25,6 +27,15 @@ async fn main() -> Result<(), Box> { // Create a client to use: let api = OnlineClient::::new().await?; + let mut follow_sub = api.blocks().subscribe_chainhead_finalized(false).await?; + // Handle all subscriptions from the `chainHead_follow`. + while let Some(event) = follow_sub.next().await { + let event = event?; + + let body = event.body().await?; + println!("[hash={:?}] body={:?}", event.hash(), body); + } + // Subscribe to the `chainHead_follow` method. let mut follow_sub = api.rpc().subscribe_chainhead_follow(false).await?;