56

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?

Lee
  • 8,548
  • 6
  • 46
  • 80
  • related: https://ethereum.stackexchange.com/questions/12950/what-are-event-topics – Lee Jan 16 '18 at 13:59
  • see also: https://media.consensys.net/technical-introduction-to-events-and-logs-in-ethereum-a074d65dd61e#.7w96id6rs – Lee Jan 16 '18 at 13:59
  • "emit" is the term used; http://solidity.readthedocs.io/en/develop/contracts.html?highlight=emit#events – Lee Mar 12 '18 at 14:27

3 Answers3

35

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 Ethereum Ontology which was recently published by Johannes Pfeffer for a very thorough explanation of many Ethereum concepts.

Pang
  • 299
  • 1
  • 3
  • 7
Thomas Jay Rush
  • 9,943
  • 4
  • 31
  • 72
  • 1
    Is it kind of like the JavaScript event which can be triggered with something happening i.e event based? –  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 03:42
  • @slebetman is it possible to revert() emitted events? – user2284570 Jul 23 '19 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 '19 at 18:42
  • Sorry, I am still a little confused. So what triggers a transaction to be recorded on the blockchain? Is it the event that triggers a process? or does the EVM have a listener for when the transfer function (required by protocol) is called? Is it necessary to call the event function? – Walter M Jan 07 '20 at 22:38
19

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.

Mikko Ohtamaa
  • 22,269
  • 6
  • 62
  • 127
3

The yellowpaper (version 7e819ec - 2019-10-20) section 6.1 Substate includes a description of:

indexable ‘checkpoints’ in VM code execution that allow for contract-calls to be easily tracked byonlookers external to the Ethereum world (such as decentralised application front-ends).

The yellowpaper preceded the event terminology, but an event is a way that DApps can get information at a specific point during smart contract (EVM) code execution. Whenever the EVM encounters a LOG opcode, Ethereum nodes emit an event that DApps and external processes can be notified of and access.

In Solidity, an emit of an event gets compiled to LOG opcodes.

eth
  • 85,679
  • 53
  • 285
  • 406