Events

Learn about events in Solidity.

Events in Solidity are a means for capturing and logging specific occurrences or state changes within a contract. Events are contracted inheritable components that allow essential information to be communicated to external programs. They are especially important for signaling changes in the state of the contract, allowing external applications to respond appropriately.

Event creation

Events are declared using the event keyword, followed by an identifier, a parameter list, and a semicolon. The parameters capture relevant values for conditional logic or informational purposes. Events are invoked within the functions of a contract. They are triggered using the emit keyword, followed by the event name and the necessary arguments.

Press + to interact
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
// Defining calling contract
contract Invoker {
// Declaring an event named invoked
event Invoked(uint value, string slang);
// Defining function to call
// getValue and getSlang functions
function trigger() public returns (uint,string memory) {
uint value = 2;
string memory greet = "Hey!";
// Emitting an event
emit Invoked(value,greet);
return (value,greet);
}
}
    ...