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:
| Rule | Code | Meaning |
|---|---|---|
| Event must be declared | V34 | emit of an unknown name is an error |
| Arity and types must match | V35 | Argument count / types must match the declaration (narrow integers may auto-cast to declared widths) |
| Pure routes cannot emit | V11 | emit is a side effect |
See also Emit Events for the action form in a route body.
EVM lowering
| Cambrian | Solidity |
|---|---|
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.