EVM Contract Listeners
EVM Contract Listeners are a powerful feature in the Gadget SDK that allow your blueprint to react to events emitted by smart contracts on EVM-compatible chains. These listeners use the alloy crate, which provides a robust and efficient way to interact with EVM chains.
Overview
EVM Contract Listeners enable your blueprint to:
- Monitor specific smart contracts for events
- React to these events in real-time
- Trigger custom logic based on the event data
EvmContractEventListener
The EvmContractEventListener is a type that listens to the Ethereum Virtual Machine (EVM) for events.
Like the TangleEventListener, the EvmContractEventListener is already implemented and ready to use. Simply register it in the job macro, and your application will automatically work with the EVM.
/// Returns x^2 saturating to [`u64::MAX`] if overflow occurs.
#[job(
id = 0,
params(x),
result(_),
event_listener(EvmContractEventListener(
instance = IncredibleSquaringTaskManager,
event = IncredibleSquaringTaskManager::NewTaskCreated,
event_converter = convert_event_to_inputs,
callback = IncredibleSquaringTaskManager::IncredibleSquaringTaskManagerCalls::respondToTask
)),
)]
pub fn xsquare(
x: u64,
) -> Result<u64, Infallible> {
Ok(x.saturating_pow(2u32))
}