Solidity Tutorial – All About Events

Jean Cvllr
10 min readJan 23, 2024
Photo by Clem Onojeghuo on Unsplash

In today’s article, we will look at Solidity event also known as logs when talking about more generically Ethereum and EVM. We will see how to use them, their definition and how logs are filtered using the event topic hash and signature, as well as some best practices regarding when these should be used.

We will also cover the check-event-interaction pattern, the famous pattern applied traditionally to re-entrancy for state variables, but we will see why such patterns should be also applied to emitting events and the potential risks and security vulnerabilities involved.

Table of Contents

- How to define an event in Solidity?
- Emitting events in functions
- Event Signature
- Event Topic Hash
- Event parameters & Indexed parameters
- Anonymous Events
- Emitting events in assembly with the LOG opcode
- The Check-Event-Interaction Pattern
- When should you emit events?

How to define an event in Solidity?

Events can be defined in Solidity using the event keyword as follow.

event RegisteredSuccessfully(address user)

When using dynamic types and multi value types like bytes , string or arrays of type as T[] , data location does not need to be specified for the parameters in the event definition.

--

--