Skip to content
Logo

Event watcher

TRON has no log-subscription RPC. EventWatcher polls new blocks, reads their transaction receipts, filters logs, and decodes matching typed events generated by tron_sol!.

use futures::StreamExt;
use tronz::{Address, contract::tron_sol};
 
tron_sol! {
    #[sol(rpc)]
    interface ITrc20 {
        event Transfer(address indexed from, address indexed to, uint256 value);
    }
}
 
let token = ITrc20::new(address, provider);
let watcher = token.Transfer_filter().watch().await?;
let mut events = watcher.confirmations(19).into_stream();
 
while let Some(event) = events.next().await {
    let transfer = event?;
    println!("{} -> {}: {}", transfer.from, transfer.to, transfer.value);
}

watch() starts after the current head; use watch_from(block) when resuming from a persisted cursor. Events are held until the configured confirmation depth (19 by default), reducing reorg exposure. The watcher polls a FullNode; the confirmation depth keeps reported events behind the chain head.

See the runnable typed event watcher example.