Skip to content

Commit

Permalink
update comments, flag subscribe_logs as non-runnable example
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnacks committed Apr 22, 2024
1 parent ec2fc48 commit f9cbbc5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Example of subscribing to blocks and watching contract events by WebSocket subscription.
//! Example of watching and polling for contract events by WebSocket subscription.
use alloy::{node_bindings::Anvil, providers::ProviderBuilder, rpc::client::WsConnect, sol};
use eyre::Result;
Expand Down Expand Up @@ -58,7 +58,7 @@ async fn main() -> Result<()> {
let _ = decrement_call.send().await?;
}

// Listen for the events.
// Poll for logs.
increment_filter
.into_stream()
.take(2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Example of subscribing to logs from the Ethereum network using an external provider.
//! Example of subscribing and listening for contract events by WebSocket subscription.
use alloy::{
primitives::{address, b256},
Expand All @@ -13,6 +13,14 @@ use futures_util::stream::StreamExt;

#[tokio::main]
async fn main() -> Result<()> {
// Set up the WS transport which is consumed by the RPC client.
let rpc_url = "wss://eth-mainnet.g.alchemy.com/v2/your-api-key";

// Create the provider.
let ws = WsConnect::new(rpc_url);
let provider = ProviderBuilder::new().on_ws(ws).await?;

// Create a filter to watch for Uniswap token transfers.
let uniswap_token_address = address!("1f9840a85d5aF5bf1D1762F925BDADdC4201F984");
let tranfer_event_signature =
b256!("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef");
Expand All @@ -21,13 +29,8 @@ async fn main() -> Result<()> {
.event_signature(tranfer_event_signature)
.from_block(BlockNumberOrTag::Latest);

let rpc_url = "wss://eth.merkle.io"; // DON'T use wss://eth.merkle.io _> this filters wrongly, tested alchemy.io's to be working fine

// Create the provider.
let ws = WsConnect::new(rpc_url);
let provider = ProviderBuilder::new().on_ws(ws).await.unwrap();

let sub = provider.subscribe_logs(&filter).await.expect("Failed to subscribe to logs");
// Subscribe to logs.
let sub = provider.subscribe_logs(&filter).await?;
let mut stream = sub.into_stream();

while let Some(log) = stream.next().await {
Expand Down

0 comments on commit f9cbbc5

Please sign in to comment.