Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
chore: fix custom provider example
Browse files Browse the repository at this point in the history
  • Loading branch information
gakonst committed Feb 2, 2023
1 parent a544d40 commit 806af08
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions examples/providers/examples/custom.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Create a custom data transport to use with a Provider.
use async_trait::async_trait;
use ethers::prelude::*;
use ethers::{core::utils::Anvil, prelude::*};
use serde::{de::DeserializeOwned, Serialize};
use std::fmt::Debug;
use thiserror::Error;
Expand Down Expand Up @@ -103,8 +103,11 @@ impl PubsubClient for WsOrIpc {

#[tokio::main]
async fn main() -> eyre::Result<()> {
// Spawn Anvil
let anvil = Anvil::new().block_time(1u64).spawn();

// Connect to our transport
let transport = WsOrIpc::connect("ws://localhost:8546").await?;
let transport = WsOrIpc::connect(&anvil.ws_endpoint()).await?;

// Wrap the transport in a provider
let provider = Provider::new(transport);
Expand All @@ -113,7 +116,7 @@ async fn main() -> eyre::Result<()> {
let block_number = provider.get_block_number().await?;
println!("Current block: {block_number}");

let mut subscription = provider.subscribe_blocks().await?;
let mut subscription = provider.subscribe_blocks().await?.take(3);
while let Some(block) = subscription.next().await {
println!("New block: {:?}", block.number);
}
Expand Down

0 comments on commit 806af08

Please sign in to comment.