Last active
May 14, 2024 11:19
-
-
Save kallydev/0d5d876cc9c4b7327e960b8b7768d81f to your computer and use it in GitHub Desktop.
Alloy log subscriber.
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
[package] | |
name = "playground" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
alloy = { git = "https://github.com/alloy-rs/alloy.git", features = ["contract", "provider-ws", "rpc-types-eth"] } | |
anyhow = "1.0.82" | |
tokio = { version = "1.37.0", features = ["full"] } | |
tracing = "0.1.40" | |
tracing-subscriber = "0.3.18" | |
tokio-stream = "0.1.15" |
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
use alloy::primitives::Address; | |
use alloy::providers::{Provider, ProviderBuilder}; | |
use alloy::rpc::types::eth::Filter; | |
use alloy::sol; | |
use alloy::sol_types::SolEvent; | |
use alloy::transports::ws::WsConnect; | |
use tokio_stream::StreamExt; | |
use tracing::info; | |
sol!( | |
#[sol(rpc)] | |
IERC20, | |
"src/abi/IERC20.json" | |
); | |
#[tokio::test] | |
async fn test() -> anyhow::Result<()> { | |
tracing_subscriber::fmt().init(); | |
let provider = ProviderBuilder::new() | |
.on_ws(WsConnect::new("wss://mainnet.gateway.tenderly.co")) | |
.await?; | |
let filter = Filter::new() | |
.address("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48".parse::<Address>()?) // USDC contract address | |
.event("Transfer(address,address,uint256)"); | |
let log_subscription = provider.subscribe_logs(&filter).await?; | |
let mut log_subscription_stream = log_subscription.into_stream(); | |
while let Some(log) = log_subscription_stream.next().await { | |
let transfer_log = IERC20::Transfer::decode_log(log.as_ref(), true)?; | |
info!(from = ?transfer_log.from, to = ?transfer_log.to, value = ?transfer_log.value, "USDC Transfer"); | |
} | |
Ok(()) | |
} |
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
2024-05-07T04:27:49.393686Z INFO playground: USDC Transfer from=0x0d0707963952f2fba59dd06f2b425ace40b492fe to=0x401763d99bf21f0344325eaadf5a86947ac031b0 value=0x0000000000000000000000000000000000000000000000000000000012075370_U256 | |
2024-05-07T04:27:49.393885Z INFO playground: USDC Transfer from=0xf89d7b9c864f589bbf53a82105107622b35eaa40 to=0x3a6fc80335001bf9472ef6ec963476feb3cdfa3c value=0x0000000000000000000000000000000000000000000000000000000011f0e540_U256 | |
2024-05-07T04:27:49.393951Z INFO playground: USDC Transfer from=0x5041ed759dd4afc3a72b8192c143f72f4724081a to=0xddd6670fc2d6a3834918eeae979fcd4f2c32a471 value=0x0000000000000000000000000000000000000000000000000000000011e1a300_U256 | |
2024-05-07T04:27:49.394015Z INFO playground: USDC Transfer from=0x7b27cd3a6592965790c503784edc8dbf08a09d75 to=0xae2d4617c862309a3d75a0ffb358c7a5009c673f value=0x00000000000000000000000000000000000000000000000000000000e9344a93_U256 | |
2024-05-07T04:27:49.394074Z INFO playground: USDC Transfer from=0x66f84462d88ee30a6ca13df25a5c626929c10bf7 to=0xae2d4617c862309a3d75a0ffb358c7a5009c673f value=0x00000000000000000000000000000000000000000000000000000007707cd400_U256 | |
2024-05-07T04:28:04.142585Z INFO playground: USDC Transfer from=0x0d0707963952f2fba59dd06f2b425ace40b492fe to=0x26dd4e608630762807ec83d202797090deb7f1e9 value=0x0000000000000000000000000000000000000000000000000000000012075370_U256 | |
2024-05-07T04:28:04.142712Z INFO playground: USDC Transfer from=0x4ed28d619f4aef6fec1a4da939bef04f65fc8d02 to=0xde1ba6469d4b729eaa140d2997b5786262501a9a value=0x00000000000000000000000000000000000000000000000000000000129e3578_U256 | |
2024-05-07T04:28:04.142786Z INFO playground: USDC Transfer from=0xa9d1e08c7793af67e9d92fe308d5697fb81d3e43 to=0x1eaf28189162778dd1f7312b2fa94ba8748caf7f value=0x00000000000000000000000000000000000000000000000000000001bf08eb00_U256 | |
2024-05-07T04:28:04.142857Z INFO playground: USDC Transfer from=0xa9d1e08c7793af67e9d92fe308d5697fb81d3e43 to=0x5f0a7764fb2f43f9341113d0d24e8b9bc7dfa028 value=0x00000000000000000000000000000000000000000000000000000000000f4240_U256 | |
2024-05-07T04:28:04.142921Z INFO playground: USDC Transfer from=0xa9d1e08c7793af67e9d92fe308d5697fb81d3e43 to=0x51c72848c68a965f66fa7a88855f9f7784502a7f value=0x000000000000000000000000000000000000000000000000000002895df34880_U256 | |
2024-05-07T04:28:04.142986Z INFO playground: USDC Transfer from=0xa9d1e08c7793af67e9d92fe308d5697fb81d3e43 to=0x498ae97f1c4faa0463e18c00bd08922af43e40ee value=0x0000000000000000000000000000000000000000000000000000000007938c7a_U256 | |
2024-05-07T04:28:04.143050Z INFO playground: USDC Transfer from=0x787b8840100d9baadd7463f4a73b5ba73b00c6ca to=0x05820214e01401c28bc6700795aed068ea098566 value=0x0000000000000000000000000000000000000000000000000000000002fdea25_U256 | |
2024-05-07T04:28:04.143115Z INFO playground: USDC Transfer from=0x222222fd79264bbe280b4986f6fefbc3524d0137 to=0xe37e799d5077682fa0a244d46e5649f71457bd09 value=0x00000000000000000000000000000000000000000000000000000022ecb25c00_U256 | |
2024-05-07T04:28:04.143221Z INFO playground: USDC Transfer from=0xe37e799d5077682fa0a244d46e5649f71457bd09 to=0x111111125421ca6dc452d289314280a0f8842a65 value=0x00000000000000000000000000000000000000000000000000000022ecb25c00_U256 | |
2024-05-07T04:28:04.143334Z INFO playground: USDC Transfer from=0x111111125421ca6dc452d289314280a0f8842a65 to=0x733c33339684f38c8aada0434751611e168255c4 value=0x00000000000000000000000000000000000000000000000000000022ecb25c00_U256 | |
2024-05-07T04:28:04.143425Z INFO playground: USDC Transfer from=0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc to=0x663dc15d3c1ac63ff12e45ab68fea3f0a883c251 value=0x0000000000000000000000000000000000000000000000000000000001da4266_U256 | |
2024-05-07T04:28:04.143490Z INFO playground: USDC Transfer from=0x663dc15d3c1ac63ff12e45ab68fea3f0a883c251 to=0x41c691aedc119197f5d0540dcb6da768240e18cf value=0x000000000000000000000000000000000000000000000000000000000003152a_U256 | |
2024-05-07T04:28:04.143564Z INFO playground: USDC Transfer from=0x663dc15d3c1ac63ff12e45ab68fea3f0a883c251 to=0xef4fb24ad0916217251f553c0596f8edc630eb66 value=0x0000000000000000000000000000000000000000000000000000000001d72d3c_U256 | |
2024-05-07T04:28:04.143637Z INFO playground: USDC Transfer from=0xff8ba4d1fc3762f6154cc942ccf30049a2a0cec6 to=0x22f9dcf4647084d6c31b2765f6910cd85c178c18 value=0x0000000000000000000000000000000000000000000000000000000000702206_U256 | |
2024-05-07T04:28:04.143744Z INFO playground: USDC Transfer from=0x22f9dcf4647084d6c31b2765f6910cd85c178c18 to=0x7afa9d836d2fccf172b66622625e56404e465dbd value=0x000000000000000000000000000000000000000000000000000000000000f344_U256 | |
2024-05-07T04:28:04.143811Z INFO playground: USDC Transfer from=0x22f9dcf4647084d6c31b2765f6910cd85c178c18 to=0x602c054249baa5307805a8c491b459d64996056b value=0x00000000000000000000000000000000000000000000000000000000006f2ec2_U256 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment