Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Events

Events declare structured log topics that a route can write with emit. On EVM they mirror the ABI event model and lower to Solidity event declarations plus emit statements.

Declaration

An event may appear at program scope (file top level) or inside an entity (alongside routes / members). Both forms are visible for emit from that entity; program-scope events are shared across entities in the file.

event Transfer(indexed src: address, indexed dst: address, amount: U256);

entity Token {
    event Approval(indexed owner: address, indexed spender: address, amount: U256);

    routes {
        transfer(dst: address, amount: U256) => [
            emit Transfer(msg::sender, dst, amount)
        ]

        approve(spender: address, amount: U256) => [
            emit Approval(msg::sender, spender, amount)
        ]
    }
}

Indexed parameters

Prefix a parameter with indexed to place it in a log topic (searchable / filterable off-chain):

event Transfer(indexed src: address, indexed dst: address, amount: U256);

On the EVM target, a non-anonymous event may have at most three indexed parameters (V36). Extra indexed fields are rejected at validation time.

Emitting

Use the emit action inside a route body:

emit Transfer(msg::sender, dst, amount)

Rules:

RuleCodeMeaning
Event must be declaredV34emit of an unknown name is an error
Arity and types must matchV35Argument count / types must match the declaration (narrow integers may auto-cast to declared widths)
Pure routes cannot emitV11emit is a side effect

See also Emit Events for the action form in a route body.

EVM lowering

CambrianSolidity
event Name(...);event Name(...); (file- or entity-scoped)
emit Name(args)emit Name(args);

Program-scope events appear at file scope in the generated Solidity; entity-scope events live on the generated entity contract.