intermediate

Events and Logs

30 min
3 objectives
Events are crucial for off-chain applications to track what happens in your contract. Let's learn how to emit events in Stylus! ## Your Task Create a contract that: 1. Defines a `Transfer` event with from, to, and amount fields 2. Emits the event when a transfer function is called 3. Tracks balances using a storage mapping ## Key Concepts - The `sol_storage!` macro can define event structures - Use `evm::log` to emit events - Events are indexed for efficient filtering

Learning Objectives

  • Define and emit events
  • Use event logging for tracking
  • Understand indexed vs non-indexed parameters
lib.rs

Click "Run Code" to validate your solution