Network
Launch Date
Consensus
Note
Sepolia
Oct 2021
PoW
Like-for-like representation of Ethereum
Görli
Jan 2019
PoA
Proof-of-Authority
Kiln
Mar 2022
PoS
Post-Merge (for ETH2), shadow fork of the mainnet
Kintsugi
Dec 2021
PoS
DEPRECATED, use Kiln; post-Merge (for ETH2)
Ropsten
Nov 2016
PoW
DEPRECATED, use Sepolia; the Merge to happen on Jun 8, 2022
Rinkeby
Apr 2017
PoA
DEPRECATED, use Görli and Görli Faucet
Kovan
Mar 2017
PoA
DEPRECATED, use Sepolia or Görli
List of active and deprecated Ethereum testnets, including Kintsugi.
Features
Optimistic rollup 
ZK-rollup 
Proof
Uses fraud proofs to prove transaction validity. 
Uses validity (zero-knowledge) proofs to prove transaction validity. 
Capital efficiency
Requires waiting through a 1-week delay (dispute period) before withdrawing funds. 
Users can withdraw funds immediately because validity proofs provide incontrovertible evidence of the authenticity of off-chain transactions. 
Data compression
Publishes full transaction data as calldata to Ethereum Mainnet, which increases rollup costs. 
Doesn't need to publish transaction data on Ethereum because ZK-SNARKs and ZK-STARKs already guarantee the accuracy of the rollup state. 
EVM compatibility
Uses a simulation of the Ethereum Virtual Machine (EVM), which allows it to run arbitrary logic and support smart contracts. 
Doesn't widely support EVM computation, although a few EVM-compatible ZK-rollups have appeared. 
Rollup costs
Reduces costs since it publishes minimal data on Ethereum and doesn't have to post proofs for transactions, except in special circumstances. 
Faces higher overhead from costs involved in generating and verifying proofs for every transaction block. ZK proofs require specialized, expensive hardware to create and have high on-chain verification costs. 
Trust assumptions
Doesn't require a trusted setup. 
Requires a trusted setup to work. 
Liveness requirements
Verifiers are needed to keep tabs on the actual rollup state and the one referenced in the state root to detect fraud. 
Users don't need someone to watch the L2 chain to detect fraud. 
Security properties 
Relies on cryptoeconomic incentives to assure users of rollup security. 
Relies on cryptographic guarantees for security. 
Start building
on Alchemy.
Sign up for free
Start building on Optimism.
Sign up for free
Start building on Arbitrum.
Sign up for free
Start building on Ethereum.
Sign up for free
Start building on Polygon.
Sign up for free
Start building on Starknet.
Sign up for free
Start building on Flow.
Sign up for free
kiln faucet
Get free Kiln ETH.
Start building today
Goerli faucet
Get free Goerli ETH.
Start building today
SEPOLIA FAUCET
Get free Sepolia ETH.
Start Building Today
mumbai faucet
Get free Mumbai Matic.
Start building today
rinkeby faucet
Get free Rinkeby
ETH.
Start building today
Start building on Ethereum.
Get started for free
Start building on Ethereum.
Get started for free
Start building on Flow.
Get started for free
Start building on Polygon.
Get started for free
Start building on Starknet.
Get started for free
Start building on Optimism.
Get started for free
Start building on Solana.
Get started for free
Start building on Solana.
Sign up for beta access
Start building on Solana.
Join the waitlist
Arbitrum logo
Start building on Arbitrum.
Get started for free
Learn
Solidity at
Alchemy
University
Get started today
curl 
https://release.solana.com/v1.10.32/solana-install-init-x86_64-pc-windows-msvc.exe 
--output 
C:\solana-install-tmp\solana-install-init.exe 
--create-dirs
Learn Solidity
SOLIDITY EVENTS OVERVIEW

What are Solidity events?

Learn How Solidity Events Work
Last Updated:
October 4, 2022
Table of Contents
Table of Contents
Table of Contents

{{learn-solidity}}

Solidity events are crucial for smart contract developers because they allow smart contracts to index variables in order to rebuild the storage stage, help to automatically update the user interface, and allow for testing of specific variables. This article will develop your understanding of Solidity events and help you deepen your understanding of the Solidity programming language.

We’ll first introduce Solidity events, then give some of their classifications, and provide examples. By the end of this article, you will be able to create a Solidity event for your next project.

What is an event in Solidity?

In Solidity, events are dispatched signals that smart contracts can fire. When you call events, they cause the arguments to be stored in the transaction’s log, which is a special data structure in the blockchain. Events notify external users, such as a listening frontend website or client application, that something has happened on the blockchain. 

What is the difference between events and functions in Solidity?

While both functions and events accept arguments and can be called, functions modify smart contracts directly while events have the role of informing services outside of the blockchain to let users know that something has happened.

Functions in Solidity allow developers to read, write, change, and store data in the smart contract. You can pass arguments or parameters into a function. You can also call a function whenever it is needed in the code.

Events also accept arguments, but these are stored in the transaction’s log, which is inaccessible to smart contracts. Contact data lives in the States trie and event data is stored in the Transaction Receipts trie, meaning contracts cannot read event data. Events are simply fired and forgotten.  

Like functions, events can be called. However, the emit keyword is used to call/dispatch events. This allows developers to know when an event or a function is being called.

What is the relationship between events and logs? 

The Ethereum Virtual Machine (EVM) has a logging function that is used to write data, including Solidity events, to a structure outside smart contracts. 

Logs and events are often referred to synonymously. Events allow you to ‘print’ information to the logging structure in a way that is more gas-efficient since the information is not stored in a storage variable, which takes up more gas. Events, or logs, live in the Transaction Receipts trie, which is inaccessible to smart contracts. 

How are events indexed in Solidity?

Solidity events are interfaces with EVM logging functionality. You can add an attribute indexed to up to three parameters. Then they appear in the structure of topics, not the data portion of the log. When parameters do not have the indexed attributes, they are ABI-encoded into the data portion of the log.

Solidity Event Types

There are two types of Solidity events: those which are indexed and those which are not. 

When parameters do not have the indexed attribute, they are ABI-encoded into the data portion of the log. These parameters form the byte array of the event. Data is encoded according to its type and can be decoded according to a schema. 

Indexed parameters are also known as “topics”, are the searchable parameters in events. The indexed parameters will allow you to search for these events using the indexed parameters as filters. You can add an attribute indexed up to 4 parameters or 3 parameters based on whether the events are anonymous or not, respectively. 

How do events work in Solidity?

Solidity events are declared, emitted, and registered.

  1. First, the event type has to be declared with the event keyword in Solidity. 
  2. Next, the event has to be emitted with the keyword emit.
  3. Anytime something in the blockchain changes, your program will automatically register this change and trigger the event 

Note: Emitting an event after declaration allows you to then ‘listen’ for the event from your application using libraries like Web3.js or Ethers.js. 

How do you declare an event in Solidity?

The declaration of an event contains the name of the event and the parameters that you want to save when you trigger the event.

First, you have to declare an event in Solidity. Then, you emit the event with the keyword emit

The following is an example of how to declare an event: 



event moneySent(address_from, address_to, unit_amount); 

The event, when triggered, will inform the external application that something on the blockchain has changed.

How are events emitted in Solidity?

After the event is defined, you can trigger the event using the keyword emit. Once an event is emitted, the arguments passed are stored in transaction logs. 

The following syntax shows you how to use emit in Solidity:



emit transfer(_from, _to, amount);

How to Listen to Events in Solidity

Once events are emitted, you can listen for them by subscribing to catch these events using ethers.js. Then dApps, or anything connected to an Ethereum JSON-RPC API, can listen to these events and act accordingly.

Solidity Event Example

The following sample code defines and emits an event for transfers. This code is applicable to an Ethereum transfer application, where the event is triggered on a transfer. Additional code can be added to allow the event, upon triggering, to update the user interface to show that a transfer has taken place. 

The next example, taken from Solidity by Example, creates an event that has two parameters: the address of the sender and the string message. When triggered, the event logs “Hello World” and “Hello EVM”. 

Keep Learning About Solidity

This article introduces you to Solidity events and provides you with explanations and resources to use for your next project. With Solidity events, you will have an easier time creating efficient smart contracts.

If you’re new to the Solidity language and you’re looking forward to building your first smart contract, secure your spot in Alchemy University's free, 7-week online Solidity programming course.

ALCHEMY SUPERNODE - ETHEREUM NODE API

Scale to any size, without any errors

Alchemy Supernode finally makes it possible to scale blockchain applications without all the headaches. Plus, our legendary support will guide you every step of the way.

Get started for free
Supernode footer
Learn Solidity
SOLIDITY EVENTS OVERVIEW

Learn Solidity: What are events?

Learn How Solidity Events Work
Last Updated:
October 4, 2022
Don't miss an update
Sign up for our newsletter to get alpha, key insights, and killer resources.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Table of Contents
Table of Contents

{{learn-solidity}}

Solidity events are crucial for smart contract developers because they allow smart contracts to index variables in order to rebuild the storage stage, help to automatically update the user interface, and allow for testing of specific variables. This article will develop your understanding of Solidity events and help you deepen your understanding of the Solidity programming language.

We’ll first introduce Solidity events, then give some of their classifications, and provide examples. By the end of this article, you will be able to create a Solidity event for your next project.

What is an event in Solidity?

In Solidity, events are dispatched signals that smart contracts can fire. When you call events, they cause the arguments to be stored in the transaction’s log, which is a special data structure in the blockchain. Events notify external users, such as a listening frontend website or client application, that something has happened on the blockchain. 

What is the difference between events and functions in Solidity?

While both functions and events accept arguments and can be called, functions modify smart contracts directly while events have the role of informing services outside of the blockchain to let users know that something has happened.

Functions in Solidity allow developers to read, write, change, and store data in the smart contract. You can pass arguments or parameters into a function. You can also call a function whenever it is needed in the code.

Events also accept arguments, but these are stored in the transaction’s log, which is inaccessible to smart contracts. Contact data lives in the States trie and event data is stored in the Transaction Receipts trie, meaning contracts cannot read event data. Events are simply fired and forgotten.  

Like functions, events can be called. However, the emit keyword is used to call/dispatch events. This allows developers to know when an event or a function is being called.

What is the relationship between events and logs? 

The Ethereum Virtual Machine (EVM) has a logging function that is used to write data, including Solidity events, to a structure outside smart contracts. 

Logs and events are often referred to synonymously. Events allow you to ‘print’ information to the logging structure in a way that is more gas-efficient since the information is not stored in a storage variable, which takes up more gas. Events, or logs, live in the Transaction Receipts trie, which is inaccessible to smart contracts. 

How are events indexed in Solidity?

Solidity events are interfaces with EVM logging functionality. You can add an attribute indexed to up to three parameters. Then they appear in the structure of topics, not the data portion of the log. When parameters do not have the indexed attributes, they are ABI-encoded into the data portion of the log.

Solidity Event Types

There are two types of Solidity events: those which are indexed and those which are not. 

When parameters do not have the indexed attribute, they are ABI-encoded into the data portion of the log. These parameters form the byte array of the event. Data is encoded according to its type and can be decoded according to a schema. 

Indexed parameters are also known as “topics”, are the searchable parameters in events. The indexed parameters will allow you to search for these events using the indexed parameters as filters. You can add an attribute indexed up to 4 parameters or 3 parameters based on whether the events are anonymous or not, respectively. 

How do events work in Solidity?

Solidity events are declared, emitted, and registered.

  1. First, the event type has to be declared with the event keyword in Solidity. 
  2. Next, the event has to be emitted with the keyword emit.
  3. Anytime something in the blockchain changes, your program will automatically register this change and trigger the event 

Note: Emitting an event after declaration allows you to then ‘listen’ for the event from your application using libraries like Web3.js or Ethers.js. 

How do you declare an event in Solidity?

The declaration of an event contains the name of the event and the parameters that you want to save when you trigger the event.

First, you have to declare an event in Solidity. Then, you emit the event with the keyword emit

The following is an example of how to declare an event: 



event moneySent(address_from, address_to, unit_amount); 

The event, when triggered, will inform the external application that something on the blockchain has changed.

How are events emitted in Solidity?

After the event is defined, you can trigger the event using the keyword emit. Once an event is emitted, the arguments passed are stored in transaction logs. 

The following syntax shows you how to use emit in Solidity:



emit transfer(_from, _to, amount);

How to Listen to Events in Solidity

Once events are emitted, you can listen for them by subscribing to catch these events using ethers.js. Then dApps, or anything connected to an Ethereum JSON-RPC API, can listen to these events and act accordingly.

Solidity Event Example

The following sample code defines and emits an event for transfers. This code is applicable to an Ethereum transfer application, where the event is triggered on a transfer. Additional code can be added to allow the event, upon triggering, to update the user interface to show that a transfer has taken place. 

The next example, taken from Solidity by Example, creates an event that has two parameters: the address of the sender and the string message. When triggered, the event logs “Hello World” and “Hello EVM”. 

Keep Learning About Solidity

This article introduces you to Solidity events and provides you with explanations and resources to use for your next project. With Solidity events, you will have an easier time creating efficient smart contracts.

If you’re new to the Solidity language and you’re looking forward to building your first smart contract, secure your spot in Alchemy University's free, 7-week online Solidity programming course.

Solidity events are crucial for smart contract developers because they allow smart contracts to index variables in order to rebuild the storage stage, help to automatically update the user interface, and allow for testing of specific variables. This article will develop your understanding of Solidity events and help you deepen your understanding of the Solidity programming language.

We’ll first introduce Solidity events, then give some of their classifications, and provide examples. By the end of this article, you will be able to create a Solidity event for your next project.

What is an event in Solidity?

In Solidity, events are dispatched signals that smart contracts can fire. When you call events, they cause the arguments to be stored in the transaction’s log, which is a special data structure in the blockchain. Events notify external users, such as a listening frontend website or client application, that something has happened on the blockchain. 

What is the difference between events and functions in Solidity?

While both functions and events accept arguments and can be called, functions modify smart contracts directly while events have the role of informing services outside of the blockchain to let users know that something has happened.

Functions in Solidity allow developers to read, write, change, and store data in the smart contract. You can pass arguments or parameters into a function. You can also call a function whenever it is needed in the code.

Events also accept arguments, but these are stored in the transaction’s log, which is inaccessible to smart contracts. Contact data lives in the States trie and event data is stored in the Transaction Receipts trie, meaning contracts cannot read event data. Events are simply fired and forgotten.  

Like functions, events can be called. However, the emit keyword is used to call/dispatch events. This allows developers to know when an event or a function is being called.

What is the relationship between events and logs? 

The Ethereum Virtual Machine (EVM) has a logging function that is used to write data, including Solidity events, to a structure outside smart contracts. 

Logs and events are often referred to synonymously. Events allow you to ‘print’ information to the logging structure in a way that is more gas-efficient since the information is not stored in a storage variable, which takes up more gas. Events, or logs, live in the Transaction Receipts trie, which is inaccessible to smart contracts. 

How are events indexed in Solidity?

Solidity events are interfaces with EVM logging functionality. You can add an attribute indexed to up to three parameters. Then they appear in the structure of topics, not the data portion of the log. When parameters do not have the indexed attributes, they are ABI-encoded into the data portion of the log.

Solidity Event Types

There are two types of Solidity events: those which are indexed and those which are not. 

When parameters do not have the indexed attribute, they are ABI-encoded into the data portion of the log. These parameters form the byte array of the event. Data is encoded according to its type and can be decoded according to a schema. 

Indexed parameters are also known as “topics”, are the searchable parameters in events. The indexed parameters will allow you to search for these events using the indexed parameters as filters. You can add an attribute indexed up to 4 parameters or 3 parameters based on whether the events are anonymous or not, respectively. 

How do events work in Solidity?

Solidity events are declared, emitted, and registered.

  1. First, the event type has to be declared with the event keyword in Solidity. 
  2. Next, the event has to be emitted with the keyword emit.
  3. Anytime something in the blockchain changes, your program will automatically register this change and trigger the event 

Note: Emitting an event after declaration allows you to then ‘listen’ for the event from your application using libraries like Web3.js or Ethers.js. 

How do you declare an event in Solidity?

The declaration of an event contains the name of the event and the parameters that you want to save when you trigger the event.

First, you have to declare an event in Solidity. Then, you emit the event with the keyword emit

The following is an example of how to declare an event: 



event moneySent(address_from, address_to, unit_amount); 

The event, when triggered, will inform the external application that something on the blockchain has changed.

How are events emitted in Solidity?

After the event is defined, you can trigger the event using the keyword emit. Once an event is emitted, the arguments passed are stored in transaction logs. 

The following syntax shows you how to use emit in Solidity:



emit transfer(_from, _to, amount);

How to Listen to Events in Solidity

Once events are emitted, you can listen for them by subscribing to catch these events using ethers.js. Then dApps, or anything connected to an Ethereum JSON-RPC API, can listen to these events and act accordingly.

Solidity Event Example

The following sample code defines and emits an event for transfers. This code is applicable to an Ethereum transfer application, where the event is triggered on a transfer. Additional code can be added to allow the event, upon triggering, to update the user interface to show that a transfer has taken place. 

The next example, taken from Solidity by Example, creates an event that has two parameters: the address of the sender and the string message. When triggered, the event logs “Hello World” and “Hello EVM”. 

Keep Learning About Solidity

This article introduces you to Solidity events and provides you with explanations and resources to use for your next project. With Solidity events, you will have an easier time creating efficient smart contracts.

If you’re new to the Solidity language and you’re looking forward to building your first smart contract, secure your spot in Alchemy University's free, 7-week online Solidity programming course.

Build web3 with Alchemy

Alchemy combines the most powerful web3 developer products and tools with resources, community and legendary support.

 Start building