Solidity Events are the same as events in any other programming language. An event is an inheritable member of the contract, which stores the arguments passed in the transaction logs when emitted. Generally, events are used to inform the calling application about the current state of the contract, with the help of the logging facility of EVM. Events notify the applications about the change made to the contracts and applications which can be used to execute the dependent logic.
Creating an event
Events are defined within the contracts as global and called within its functions. Events are declared by using the event keyword, followed by an identifier and the parameter list, and ends with a semicolon. The parameter values are used to log the information or for executing the conditional logic. Its information and values are saved as part of the transactions inside the block. There is no need of providing variables, only datatypes are sufficient. An event can be called from any method by using its name and passing the required parameters.
event <eventName>(parameters) ;
// Solidity program to demonstrate // creating an event pragma solidity ^0.4.21; // Creating a contract contract eventExample { // Declaring state variables uint256 public value = 0; // Declaring an event event Increment(address owner); // Defining a function for logging event function getValue(uint _a, uint _b) public { emit Increment(msg.sender); value = _a + _b; } } |
Output:

Recommended Posts:
- Solidity - Types
- Solidity - Functions
- Solidity - Inheritance
- Solidity - Polymorphism
- Solidity - View and Pure Functions
- Solidity - Encapsulation
- Solidity - Abstract Contract
- How to Install Solidity in Windows?
- Solidity - While, Do-While, and For Loop
- Solidity - Break and Continue Statements
- Solidity - Variables
- Solidity - Error Handling
- Steps to Execute Solidity Smart Contract using Remix IDE
- Solidity - Arrays
- Solidity - Enums and Structs
- Solidity - Libraries
- Introduction to Solidity
- Solidity - Constructors
- Solidity - Decision Making Statements
- Solidity - Operators
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

