Events
Part of the Fundamentals section of Coddy's Solidity journey. Lesson 48 of 53.
An event records a log entry for off-chain applications to observe. Declare its name and typed fields at contract scope, then use emit to produce the log. Events are different from state variables and from the practice console.
Declare this at contract scope:
event Counted(uint256 value);Use it inside the provided main function:
emit Counted(17);
console.log(uint256(17));Counted produces an event log with one numeric field. The console call separately prints seventeen in this exercise runner. Event logs are not included in the text-output tests, so a correct exercise must emit the event and print the requested value separately.
Declare events with event and produce their logs with emit.
Challenge
EasyDeclare event Updated(uint256 value). Emit Updated(amount), then print amount.
The tests pass arguments to main in this order: uint256 amount. Each test starts with fresh contract state.
Use console.log for the requested output. Print only the requested values, one per line, with no extra labels unless the task specifies them.
Try it yourself
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/console.sol";
contract Main {
function main(uint256 amount) external {
// Write your solution here.
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
Practice on your own: Solidity playground