Reading assignment - Solidity Events


#61
  1. How are events declared?
    event Deposit (address indexed _from,
    bytes32 indexed _id,
    uint _value);
  2. How can we emit events?
    function deposit(bytes32 _id){
    Deposit(msg.sender, _id, msg.value);
    }
  3. How and where do we listen for events?
    in the user interface of a dapp; by using web3 api

#62

1.How are events decalred?
Events are declared with the keyword ‘event’, giving a name to the event, as well as its arguments and then code within it.

2.How can we emit events?
We can emit events by using the keyword ‘emit’ followed by the name of the event and the arguments within the event.

3.How and where do we listen for events?
We can listen for event in the JavaScript frontend of our Dapp. To listen to an event, we can either code in an observable change, or pass a callback in JavaScript to access the EVM logging facilities.


#63

How are events declared?
With the ‘event’ keyword

How can we emit events?
By using the event name and arguments
Eventname(arg1, arg2 , …);

How and where do we listen for events?
In 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.


#64
  1. How are events declared?
    Using ‘event’ keyword

event Deposit();

  1. How can we emit events?
    By calling it in a function

  2. 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


#65

1 With ‘event’ keyword.

contract Contract {
event Deposit(
);
}

2 Like any other function.

event Deposit(uint _valie) //we can define variables
emit Deposit(…) //we call the event using ‘emit’

3 One example:

var event = clientReceipt.Deposit(); //we declare event
event.watch(function(error, result){ //we watch for an error and result.
if (!error)
console.log(result); //If an error occurs we print to the console with ‘console.log(result)’
});

We can do this more condensed:

var event = clientReceipt.Deposit(function(error, result) { //we basically put event.watch instide the Deposit brackets.
if (!error)
console.log(result);
});


#66

How are events declared?
Inside of a contract we can have something like:

event MyEvent (arg1, arg2)

How can we emit events?
By calling it, e…g.:

MyEvent (par1, par2)

How and where do we listen for events?
We can listen for event in the JavaScript frontend of our Dapp. We can pass a callback in JavaScript to access the EVM logs.


#67
  1. How are events declared?
    A function of type ‘event’ is declared which specifies the event’s attributes.

  2. How can we emit events?
    Invoke the function defined above and pass in the matching attributes.

  3. How and where do we listen for events?
    In the UI/Javascript layer that interacts with the smart contract via the ‘watch’ handler that is built into the event declared above.


#68
  • Events are declared as follow:
    event NAME_OF_THE_EVENT(
    type NAME_OF_THE_ARGUMENT,
    type NAME_OF_THE_ARGUMENT,

    );

  • Events are emitted within functions inside contracts.

  • JS DAPPs have a built-in function that listen to events and with which the smart contract communicates through the event object provided by Ethereum.


#69
  1. How are events declared?
    In your contract, you can declare an event with the Event keyword.
  2. How can we emit events?
    By calling the event in a function.
  3. How and where do we listen for events?
    We can listen for these events in our java frontend that is called via the EVM/log transaction file

#70

1. How are events declared
event EventName( Varaible type eg address);

2.How can we emit events
function() Whatever {
emit EventName(Variable Type eg msg.sender)
}

  1. You can view events in the debug window in remix or using a javascript watcher on the frontend.

#71
  1. The events are declared by event keyword + the name of event inside the contract
    event TestEvent(parameter1, parameter 2…)
  2. Events can be emited inside the function by calling TestEvent (arguments)
  3. There are 2 ways to listen for the events in JS app:
  • watch method:
    event.watch(function(error, result){ });
  • Passing the callbacks directly to the event:
    event(function(error, result){ });

#72

1. How are events declared?
event MyEvent {
address indexed from; // indexed -> possible to search for indexed arguments (up to 3 possible)
uint32 indexed id;
uint value;
}

2. How can we emit events?
function someFunction(uint32 id) {
MyNewEvent(msg.sender, id, msg.value);
}

3. How and where do we listen for events?
You can watch for the changes in the Javascript API:
var event = SomeContract.MyEvent();

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


#73
  1. How are events declared?
    Events are declared by entering the keyword event followed by the EventName you assign to the event followed by the arguments of the event (in parentheses)
    For example:

event car(string make, string model, uint yearProduced);

  1. How can we emit events?
    We can emit events by entering the keyword emit followed by the name of the event we wish to trigger followed by the arguments of the event (in parentheses). We place this statement into a function and call the function.
    For example:

    Function deposit((bytes32 _id) public payable {
    emit Deposit(msg.sender, _id, msg.value);
    }

  2. How and where do we listen for events?
    We listen for events in the javascript portion of the UI. Specifically, we can either:
    a. Use the .watch method on the event that we declared in the contract, or
    b. Pass a callback to start watching immediately

For example, let’s create a contract called Sportfishing, define the event Fishing in the contract, and include the event in a setter function:

pragma solidity ^0.4.0;

contract Sportfishing {

string fSpecies;
uint fSize;

event Fishing(string fishSpecies, uint fishSize);

  function setFishing(string _fSpecies, uint _fSize) public {
fSpecies = _fSpecies;
fSize = _fSize;
Fishing(_fSpecies, _fSize);
  }

// getter function ….

}

Approach (a) .watch

Now let’s create a javascript Listener code snippet for a web page UI:

var fishingEvent = Sportfishing.Fishing();

 fishingEvent.watch(function(error, result){
         if (!error) {
	callback code }
        else {
	error code}

Approach (b) Pass a callback to start watching immediately

var event = Sportfishing.Fishing(function(error, result) {
if (!error)
console.log(result);
});


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

  2. How can we emit events?
    Events can be emits by calling a function.

  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.


#75
  1. event myEvent{args};

  2. It is called by itself: myEvent(args);

  3. They are logged and can be called with the JavaScript API.


#76
  1. Events are declared as follows

event Deposit(
address indexed _from,
bytes32 indexed _id,
uint _value
);

  1. Events are emitted from within a function as follows

function deposit(bytes32 id) {
Deposit (msg.sender, _id, msg.value);
}

  1. The callback and watch keywords can be used in the front end application to listen for the event.

#77

1. How are events declared? calling event

2. How can we emit events? by calling the given event function

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


#78
  1. How are events declared?
    with the ‘event’ keyword
  2. How can we emit events?
    using keyword ‘emit’ eventname
  3. How and where do we listen for events?
    we can listen for events within JavaScript with callbacks

#79

How are events declared?

event EventName(

address indexed _from,

bytes32 indexed _id,

uint _value

);

How can we emit events?

  • EventName(…);

How and where do we listen for events?

  • We can use event,watch using the JavaScript API
  • Or pass a callback to start watching immediately

#80
  1. How are events declared?

    Using event EventName ()

  2. How can we emit events?

    In conjunction with the previous declaration:
    Using event EventName (), to decalare the event.

    and then:
    EventName(arguments) to call the event.

  3. How and where do we listen for events?

    Using the watch method in the javascript frontend.