This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use ethers::prelude::*; | ||
use eyre::Result; | ||
use serde::{Deserialize, Serialize}; | ||
use std::sync::Arc; | ||
|
||
const WSS_URL: &str = "wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27"; | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize, EthEvent)] | ||
pub struct Transfer { | ||
#[ethevent(indexed)] | ||
pub from: Address, | ||
#[ethevent(indexed)] | ||
pub to: Address, | ||
pub tokens: U256, | ||
} | ||
|
||
/// This example shows how to subscribe to events using the Ws transport for a specific event | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let provider = Provider::<Ws>::connect(WSS_URL).await?; | ||
let provider = Arc::new(provider); | ||
let event = Transfer::new::<_, Provider<Ws>>(Filter::new(), Arc::clone(&provider)); | ||
let mut transfers = event.subscribe().await?.take(5); | ||
while let Some(log) = transfers.next().await { | ||
println!("Transfer: {:?}", log); | ||
} | ||
|
||
Ok(()) | ||
} |