ethers-rs/ethers/examples/watch_blocks.rs

15 lines
390 B
Rust

use ethers::prelude::*;
use std::time::Duration;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let ws = Ws::connect("ws://localhost:8546").await?;
let provider = Provider::new(ws).interval(Duration::from_millis(2000));
let mut stream = provider.watch_blocks().await?.stream();
while let Some(block) = stream.next().await {
dbg!(block);
}
Ok(())
}