Reading assignment - Solidity Events

Welcome to the discussion about the reading assignment about Solidity Events

Leave your answers to the questions below in this thread. If you have any questions or you want to discuss something connected to the assignment feel free to do it in this thread as well, but please keep everything to the topic.

  1. How are events declared?
  2. How can we emit events?
  3. How and where do we listen for events?
  1. Events are declared in a smart contract with the ‘event’ keyword.
  2. An event is emitted within a function’s execution by calling the given event function.
  3. We listen for events within the front-end implementation that interacts with the smart contract. A callback is provided which will be executed when the event is triggered.
1 Like

1.Event is declared in the the contract with the EVENT keyword.
2. An event is emitted within a function by calling the declared event function.
3. Events are used as a medium of interaction with the DAPP front end.Events can be used in the front end code for interaction.

1. How are events declared?
event MyEvent(args...);

2. How can we emit events?
By calling it in a function :
MyEvent(args...);

3. How and where do we listen for events?
We can listen an event in the front by using a watch or by using a callback function.

2 Likes

How are events declared?
event EventName(address indexed _from, bytes32 indexed _id, uint _value);
How can we emit events?
EventName(args...);
How and where do we listen for events?
EVM logging facilities can be used to “call” JavaScript callbacks in the user interface of a dapp

1 Like
  1. How are events declared?
    In your contract, you can declare an event for example as follows:
    event YourEvent(uint _someParameter);

  2. How can we emit events?
    By triggering the event in a function.
    emit YourEvent(…);

  3. How and where do we listen for events?
    We can listen for these events in our JavaScript frontend (event.watch(...) or using callbacks) which will be called by the EVM logging facilities if an event is triggered.

1 Like
  1. Events, in a smart contract, are declared with the ‘event’ keyword.
    For instance,
    event EventName(parameters);

  2.    EventName(arguments);
    
  3. EVM logging facilities can be used to “call” JavaScript callbacks in the user interface of a dapp

// watch for changes
event.watch(function(error, result){
if (!error)
console.log(result);
});

OR

// Or pass a callback to start watching immediately
var event = clientReceipt.Deposit(function(error, result) {
if (!error)
console.log(result);
});

1 Like

1.How are events declared?
Ans: Events are declared using ‘event’ keyword in smart contracts as below.
event Myevent(datatype var1, datatype var2);

2. How can we emit events?
Ans: We an emit events using keyword ‘emit’ eventname.
Eg: emit Myevent(datatype var1, datatype var2);

3. How and where do we listen for events?
Ans: We listen for events in the front end of a Dapp. A callback is provided which will be executed when the event is triggered.

2 Likes

1. How are events declared? By using the event keyword followed by the event name and arguments.

2. How can we emit events? By using the emit keyword followed by the event name and arguments.

3. How and where do we listen for events? By using JavaScript callbacks in the user interface of the dapp, we can listen to these events.

1 - Events will be created once you use the reserved key ‘event’ - event eventName(string x, uint y);
2 - To emit events, just use eventName(“stringValue”, 10);
3 - There is a callback in javascript API that helps us to listen the events

  1. How are events declared?
    By using event keyword_then giving arguments for it.

    event EventName (arguments);

  2. How can we emit events?

    EventName (arguments);

  3. How and where do we listen for events?
    Through EVM log which call back/post/inform Javascript API UI that EventName has happened.

How are events declared?
- They are allowed up to 3 indexed types and are declared in the following way:

event TestEvent (arguments);

How can we emit events?
- We can call them like our other functions

TestEvent(arguments);

How and where do we listen for events?
- We can listen for events within JavaScript with callbacks.

  1. event nameOfEvent (arguments, arguments1, arguments 2);
  2. nameOfEvent (arguments, arguments1, arguments 2);
  3. In a front end Decentrilized app, there you give a callback, the callback will run when nameOfEvent is triggered
  1. How are events declared?
    Events are declared with the keyword event (<args … >);
  2. How can we emit events?
    Events are emitted by calling the function (<args …>)
  3. How and where do we listen for events?
    We listen to events in fron end implementations that interact with the smart contract.
    A callback is provided that is being executed when the event is triggered

1- We can declare events with the ‘event’ word like this:
event EventName(
param1Type param1Options param1Name,
param2Type param2Options param2Name,

};

2- EventName(argument1, argument2, …);

3- We can listen for the events in our JS app in two ways:
- Using the watch method:
event.watch(function(error, result){ });
- Passing the callbacks directly to the event:
event(function(error, result){ });

1 Like

Didn’t understand this section very well. Very good answer, helped me understand.

How are events declared?

Events are declared like so (taken from):

event eventName(parameter1, parameter2, parameter3, … etc.);

How can we emit events?

To emit the above event, we call it like so:

emit eventName(parameter1, parameter2, parameter3, … etc.);

How and where do we listen for events?

The front-end of our Dapp will be listening for the event using the JavaScript API.

  1. events are declared in the smart contract : event eventName (parameters)
  2. we can emit an event by calling it somewhere in our code : eventName (parameters)
  3. we listen to events from the API which interacts with our smart contract, for example the Javascript API.

1. How are events declared?
Events are declared using the “event” keyword, followed by the name of the event and the arguments.

2. How can we emit events?
We can emit events by calling the event name in the code, and passing arguments if applicable.

3. How and where do we listen for events?
The user interface of a dapp listens for the events. The event uses EVM logging facilities, which can be used to call JavaScript callbacks to notify the front end that an event has occurred.

1. event SampleEvent();

2. emit SampleEvent();

3. The arguments of events are stored in the transaction’s log which is a special data structure in the blockchain. JavaScript callbacks in the user interface of a dapp can be used to listen to events.