Skip to content
Related Articles

Related Articles

Improve Article

What are Events in Solidity?

  • Last Updated : 10 Jul, 2020

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:
Creating an Event

My Personal Notes arrow_drop_up
Recommended Articles
Page :