Vyper theorytheory 0/50 · 0%
Events · easy

20. Events and log

Declaring and emitting logs for off-chain consumers.

Events are declared with the `event` keyword and emitted with `log`. Indexed fields let off-chain listeners filter efficiently by topic, exactly as in Solidity.

event Deposited:
    sender: indexed(address)
    amount: uint256

@external
@payable
def deposit():
    self.balances[msg.sender] += msg.value
    log Deposited(sender=msg.sender, amount=msg.value)

Events cost far less gas than storage and are the standard way for a front-end or indexer to reconstruct contract history without re-reading the whole state.

Check your understanding

  1. 1. Which keyword emits an event in Vyper?

  2. 2. What does marking a field indexed(...) enable?

  3. 3. Why prefer events over storage for historical data?