Open-Source Solidity Programming • Foundational • Estimated study time: 45 minutes.
An Ethereum application may need to display historical updates without asking a contract to store a growing array of every past measurement. Solidity events expose transaction logs for external software to retrieve and interpret. This lesson extends storage and memory and mappings.
Learning objectives
Declare and emit events; distinguish topics, log data and persistent contract state; filter indexed addresses; explain rollback and chain reorganizations; estimate the raw gas cost of a simple log.
Forge College tutorial on event declarations, emission and inspecting transaction logs.
Events versus storage
The Solidity documentation explains that events provide an abstraction over EVM logging. A conventional non-anonymous event can contain up to three indexed parameters; the first topic is the Keccak-256 hash of the canonical event signature. Static indexed types occupy their own 32-byte topic; dynamic indexed values are represented by a hash rather than the recoverable original text. Non-indexed values are ABI encoded in the log data. Contracts cannot directly read historical logs using ordinary Solidity operations.

Worked example: recording a reading
Use the structure introduced in contract structure and the function visibility lesson. This local-only demonstration records an unsigned value per caller. It is not an authenticated telemetry system.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract ReadingLog {
mapping(address => uint256) public latest;
event ReadingRecorded(address indexed reporter, uint256 value);
function record(uint256 value) external {
latest[msg.sender] = value;
emit ReadingRecorded(msg.sender, value);
}
function recordThenRevert(uint256 value) external {
latest[msg.sender] = value;
emit ReadingRecorded(msg.sender, value);
revert("demo rollback");
}
}
In Remix, select a Solidity 0.8.x compiler compatible with the pragma and deploy to a local simulated VM. Call record(42), then inspect latest for the sender and the transaction logs. Expect topic 0 to identify ReadingRecorded(address,uint256), topic 1 to encode the sender and the 32-byte data field to contain 42. Call recordThenRevert(99): expect failure, unchanged latest and no surviving event from that reverted call. These are expected outcomes from language semantics, not executed tests; a Solidity compiler and EVM runtime were unavailable during preparation.
Raw log gas
For a conventional EVM LOG operation, G = 375 + 375t + 8b, where t is the number of topics and b the number of bytes of log data. Here t = 2 and b = 32, so G = 1,381 gas. This excludes memory expansion, storage writes, transaction overhead and other execution costs. It is not a complete transaction fee estimate.
Community discussion of topic filtering and gas trade-offs. Treat the protocol specification as authoritative.
Safety and exercises
Events are public and cannot be used to hide secrets. An indexer should check contract address, chain identity, receipt status and confirmation policy; reconcile reorganizations before treating events as final. Avoid production deployments, real funds and private keys for this exercise.
Exercises: A. How many topics does ReadingRecorded emit? B. Can a contract directly read an old event? C. Does a reverted call retain its log? D. What is raw log gas with one topic and 64 bytes? Answers: A. Two. B. No. C. No. D. 1,262 gas. Additional reference: Ethereum event tutorial. Featured cover is conceptual artwork.
Editor’s Note: We volunteer daily to ensure the credibility of the information on this platform is Verifiably True. If you would like to support to help further secure the integrity of our research initiatives, please scan the QR code below

For mobile scanning, open the article on another display and scan the QR code with a Bitcoin wallet. The voluntary donation amount is 5,000 sats. Verify the receiving address 3C9o19EH5HSiwEPyCTmEKzxhNCbo2X6TTb before sending.
BitcoinVersus.Tech publishes technology and financial journalism for informational purposes and does not provide financial, investment, or legal advice.

Leave a Reply