2021-08-30 11:00:30 +00:00
|
|
|
use ethers::{prelude::*, utils::Ganache};
|
2020-06-22 08:44:08 +00:00
|
|
|
use std::time::Duration;
|
2020-06-17 18:01:20 +00:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> anyhow::Result<()> {
|
2021-08-30 11:00:30 +00:00
|
|
|
let ganache = Ganache::new().block_time(1u64).spawn();
|
|
|
|
let ws = Ws::connect(ganache.ws_endpoint()).await?;
|
2020-06-22 08:44:08 +00:00
|
|
|
let provider = Provider::new(ws).interval(Duration::from_millis(2000));
|
2021-08-30 11:00:30 +00:00
|
|
|
let mut stream = provider.watch_blocks().await?.take(5);
|
2020-06-17 18:01:20 +00:00
|
|
|
while let Some(block) = stream.next().await {
|
|
|
|
dbg!(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|