pragma solidity ^0.4.24;

contract assignment2{

  event ageread(address,int);
  function getage(address peridentifier) public returns(uint){
    human = mystruct("adam",10); //using struct mystruct
    ageread(peridentifier,stateintvariable); //stateintvariable is age
  • Events are used to communicate the outside world what happens during contract execution.
    – Nulik
    Aug 19, 2018 at 16:35

4 Answers 4


Events are to publish actions to listeners outside the blockchain. Smart contracts themselves cannot listen to any events.

All information in the blockchain is public and any actions can be found by looking into the transactions close enough but events are a shortcut to ease development of outside systems in cooperation with smart contracts. They are also indexable, meaning you can search for them. So whenever something happens within your smart contract which some system outside the blockchain should know about you should emit an event and the outside system can listen for such events.

Events are secure in a way that no other smart contract can fake events from your contract. So if you are listening to events from your contracts address and you receive such event you can be sure it was your contract which emitted it.

  • return is also going to do the same thing as when we emit an event? Aug 19, 2018 at 16:49
  • 1
    No, return is used to return a value from a function. They are not so easily available as events and you can emit multiple events from one function Aug 19, 2018 at 17:31

From the docs:

Events allow the convenient usage of the EVM logging facilities, which in turn can be used to “call” JavaScript callbacks in the user interface of a dapp, which listen for these events.

Events allow clients, (dapps) to monitor and react to what's happening to a smart contract.

Events are included in the transaction logs of the same block that fired the event.


There are 3 main use cases for events and logs:

  1. Smart contract return values for the user interface

  2. Asynchronous triggers with data

  3. A cheaper form of storage

Read this article for more details.

  • I have no idea why that article claims function return values to be events. They are not the same as events emitted from functions with the emit keyword. Aug 20, 2018 at 5:44
  • In a recent release (v0.4.21 at 8th March 2018), emit keyword has been introduced to emit the event. This will help to differentiate the functions from the event. Aug 20, 2018 at 5:48
  • Read the following question to understand importance of events in solidity ethereum.stackexchange.com/questions/51039/… Aug 20, 2018 at 5:50

Besides, event will be recored in ethereum transaction's receipts; then explorer page like http://etherscan.io can read the receipt and display the internal transaction in smart contracts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.