What are Events in Solidity?

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;


Creating an Event

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.