47

What is an Event?

Are they only used in Solidity?

How are events defined?

How are events initiated?

Is there a standard term for an event's invocation (do you say an event "happened", "was called", "was invoked","triggered")?

Where in the block header does an Event end up?

Relevant:

How to implement events in solidity

Where do contract event logs get stored in the Ethereum architecture?

26

The blockchain is a list of blocks which are fundamentally lists of transactions. Each transaction has an attached receipt which contains zero or more log entries. Log entries represent the result of events having fired from a smart contract.

In the Solidity source code, to define an event, you mark it thus by preceding it with the event keyword (similar in usage to the function keyword). You then call or fire the event in the body of whatever function you wish to cause to generate the event. (I doubt there is a standard wording for it). You may fire events from any function using the emit keyword.

Someone can probably add information on how to 'listen' for events in your DAPP. It uses the filtering functionality of Web 3.0

Check out the Etheruem Ontology which was recently published by Johannes Pfeffer for a very thourough explanation of many Ethereum concepts.

  • 1
    Is it kind of like the JavaScript event which can be triggered with something happening i.e event based? – fuddin May 20 '18 at 17:56
  • 1
    Yes. It is. Filler. – Thomas Jay Rush May 20 '18 at 21:44
  • 3
    @FahadUddin In it's most basic form, an event is EXACTLY printing a log. Therefore it is kind of like Javascript's console.log. That's it, nothing more, nothing less. In Solidity it has zero other purpose than logging the event to the blockchain. However, you can listen to events in real-time from outside code so you can use events as a sort of push notification. – slebetman Jun 21 '18 at 3:42
  • @slebetman is it possible to revert() emitted events? – user2284570 Jul 23 at 17:42
  • If the transaction reverts no events are generated. If the transaction does not revert , the event is part of the chain immutably. You can’t get it back. – Thomas Jay Rush Jul 23 at 18:42
14

Events are dispatched signals the smart contracts can fire. DApps, or anything connected to Ethereum JSON-RPC API, can listen to these events and act accordingly. Event can be indexed, so that the event history is searchable later.

An example event from a wallet contract is:

event Deposit(address from, uint value);

The application (dapp, web application, other) interested in deposits to a wallet contract would listen to this event. The application would connect to Ethereum node over JSON-RPC and either watch (wait) for the event to happen or read all the past events to sync up the application internal state with Ethereum blockchain.

  • Just a side question, can emited events to log be reverted? – user2284570 Jul 23 at 20:39
  • The whole chain state rolls back on a reorganisation or none of it rolls back. Individual events cannot be reverted. – Mikko Ohtamaa Jul 24 at 7:51
  • I mean if I use revert() it will roll back events like Transfer() right? – user2284570 Jul 24 at 10:20
  • Yes, it will roll back with everything else. There can be only one truth and transactions either completely full or none of it - atomic manner. – Mikko Ohtamaa Jul 24 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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