fix: examples (#2207)

* fix: examples

* fix: subscribe instead of watch
This commit is contained in:
DaniPopes 2023-02-28 02:59:05 +01:00 committed by GitHub
parent 47b56a65b1
commit 9e443fc216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 13 deletions

View File

@ -14,7 +14,7 @@ abigen!(
]"#, ]"#,
); );
const WSS_URL: &str = "wss://eth.llamarpc.com"; const WSS_URL: &str = "wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27";
const WETH_ADDRESS: &str = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; const WETH_ADDRESS: &str = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
#[tokio::main] #[tokio::main]

View File

@ -17,7 +17,9 @@ abigen!(
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
let client = Provider::<Ws>::connect("wss://eth.llamarpc.com").await?; let client =
Provider::<Ws>::connect("wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27")
.await?;
let client = Arc::new(client); let client = Arc::new(client);

View File

@ -5,7 +5,7 @@ use ethers::{
use eyre::Result; use eyre::Result;
use std::sync::Arc; use std::sync::Arc;
const HTTP_URL: &str = "https://eth.llamarpc.com"; const HTTP_URL: &str = "https://rpc.flashbots.net";
const V3FACTORY_ADDRESS: &str = "0x1F98431c8aD98523631AE4a59f267346ea31F984"; const V3FACTORY_ADDRESS: &str = "0x1F98431c8aD98523631AE4a59f267346ea31F984";
const DAI_ADDRESS: &str = "0x6B175474E89094C44Da98b954EedeAC495271d0F"; const DAI_ADDRESS: &str = "0x6B175474E89094C44Da98b954EedeAC495271d0F";
const USDC_ADDRESS: &str = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; const USDC_ADDRESS: &str = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";

View File

@ -6,7 +6,7 @@
use ethers::prelude::*; use ethers::prelude::*;
const WSS_URL: &str = "wss://eth.llamarpc.com"; const WSS_URL: &str = "wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27";
#[tokio::main] #[tokio::main]
async fn main() -> eyre::Result<()> { async fn main() -> eyre::Result<()> {

View File

@ -10,7 +10,9 @@ use std::sync::Arc;
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
let client: Provider<Ws> = Provider::<Ws>::connect("wss://eth.llamarpc.com").await?; let client: Provider<Ws> =
Provider::<Ws>::connect("wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27")
.await?;
let client = Arc::new(client); let client = Arc::new(client);
let last_block = client.get_block(BlockNumber::Latest).await?.unwrap().number.unwrap(); let last_block = client.get_block(BlockNumber::Latest).await?.unwrap().number.unwrap();

View File

@ -1,15 +1,13 @@
use ethers::providers::{Middleware, Provider, StreamExt, Ws}; use ethers::providers::{Middleware, Provider, StreamExt, Ws};
use eyre::Result; use eyre::Result;
use std::time::Duration;
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
let ws_endpoint = "wss://eth.llamarpc.com"; let provider =
let ws = Ws::connect(ws_endpoint).await?; Provider::<Ws>::connect("wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27")
let provider = Provider::new(ws).interval(Duration::from_millis(2000)); .await?;
let mut stream = provider.watch_blocks().await?.take(1); let mut stream = provider.subscribe_blocks().await?.take(1);
while let Some(block) = stream.next().await { while let Some(block) = stream.next().await {
let block = provider.get_block(block).await?.unwrap();
println!( println!(
"Ts: {:?}, block number: {} -> {:?}", "Ts: {:?}, block number: {} -> {:?}",
block.timestamp, block.timestamp,

View File

@ -46,5 +46,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
} }
async fn get_client() -> Provider<Ws> { async fn get_client() -> Provider<Ws> {
Provider::<Ws>::connect("wss://eth.llamarpc.com").await.unwrap() Provider::<Ws>::connect("wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27")
.await
.unwrap()
} }

View File

@ -10,7 +10,9 @@ use std::sync::Arc;
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
let client = Provider::<Ws>::connect("wss://eth.llamarpc.com").await?; let client =
Provider::<Ws>::connect("wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27")
.await?;
let client = Arc::new(client); let client = Arc::new(client);
let last_block = client.get_block(BlockNumber::Latest).await?.unwrap().number.unwrap(); let last_block = client.get_block(BlockNumber::Latest).await?.unwrap().number.unwrap();