Skip to main content

handler

Attribute Macro handler 

Source
#[handler]
Expand description

Attribute macro for handler functions.

Generates the extern "C" wrapper that graph-node calls, reading the EthereumEvent from AS memory via graph_as_runtime::ethereum::read_ethereum_event, constructing the typed event via EventType::from_raw_event, and delegating to the user’s handler implementation.

graph-node enforces strict return-type rules on exported WASM functions:

  • Event handlers must return () (void) — use #[handler]
  • Block handlers must return i32 — use #[handler(block)]

§Signature

The user’s function must take two parameters:

  • First: the event/block type (e.g. TransferEvent) — read from AS memory
  • Second: ctx: &graphite::EventContext — block/tx metadata

§Examples

// Event handler — WASM export returns void
#[handler]
pub fn handle_transfer(event: &ERC20TransferEvent, ctx: &graphite::EventContext) {
    // Handler logic here
}

// Block handler — WASM export returns i32
#[handler(block)]
pub fn handle_block(block: &EthereumBlock, ctx: &graphite::EventContext) {
    // Block handler logic here
}