Reading assignment - Solidity Events

#81

1. How are events declared?
event EventName ( ... );

2. How can we emit events?
emit EventName( ... );

3. How and where do we listen for events?
Applications can a) subscribe and b) listen to events via the RPC (Remote Procedural Call) interface of an Ethereum client.

1 Like

#82

1. How are events declared?
Events are defined by the “event” keyword and can be fired within a function body.

2. How can we emit events?
To emit an event (invoke it inside a function body) we use the “emit” keyword followed by the eventname.

3. How and where do we listen for events?
Inside the contract we define what functions have to invoke what event. Outside the contract (in the
programming language of the app you want to implement using the contract) you can watch for those
events.

First we define the event:
var <eventname> = <variable used for contract>.<eventname inside contract>()

Then we can watch for the event:

<eventname>.watch(function(error, result){
     if (!error)  
        <do actions if no errors occurred>;
    else
       <do actions if errors occurred>;
});
2 Likes

#83
  1. Events are declared with “event eventName { };”

  2. Declared events are emitted via “emit eventName (parameters);”

  3. Applications can subscribe and listen to these events through the RPC interface of an Ethereum client. The code is “event.watch(){};”

1 Like

#84
  1. How are events declared?
    With the event keyword in smart contract.
  2. How can we emit events?
    An event is emitted within a function by calling the event functions.
  3. How and where do we listen for events?
    Event is used to interact with dapp fron end. Events can be used in the front end code for interactions.
1 Like

#85
  1. How are events declared? Use the keyword event followed by the name of the event, enclose its contents with parentheses, and end with a semi-colon. Entries inside of the event are separated by comma.
  2. How can we emit events? Use the emit keyword, followed by the name of the event and the arguments (if any) in parentheses.
  3. How and where do we listen for events? Applications can subscribe and listen to events through the remote procedure call (RPC) interface of an Ethereum client.
1 Like

#86
  1. How are events declared?
    event EventName(arguments);

  2. How can we emit events?
    EventName(arguments);

  3. How and where do we listen for events?
    Though a callback in Javascript API, in the user interface of the dapp, we can listen to these events.

1 Like

#87

1.How are events declared?

event EventNameHandle( Indexed returned Object -up to 2- , Object -additional- , Function -optional-);

2. How can we emit events?

emit EventNameHandle(Object, Object)

3. How and where do we listen for events ?
EventNameHandle.watch

1 Like

#88
  1. How are events declared?
  • event NameOfEvent(
    // Arguments
    );
  1. How can we emit events?
  • NameOfEvent(
    // Arguments
    );
  1. How and where do we listen for events?
  • We can listen for events by introducing a JavaScript callback, in which case we would listen to the event on the front end of an application // PLEASE CORRECT IF THIS IS NOT ACCURATE
1 Like

#89
  1. event Deposit(param1, param2, …); <= with the keyword event followed by the event name
  2. By using emit keyword followed by the event name like below.
function aFunction() {
  emit Deposit();
}
  1. We listen to the events outside the contracts because they exist as logs, using web3 libraries.
1 Like

#90
  1. Event are inheritable members of of contracts that are declared with the keyword ‘ event’.

  2. We use the keyword ‘emit’ followed by the name of the event in our function and any associated arguments in parenthesis.

  3. One possible way is through a callback function.

1 Like

#91
1. How are events declared?

Events are declared using the event keyword, such as event [name of event] (param1 of event to be logged, param 2 of event to be logged, …)
They need to be declared outside a function, their name must be different from a function names, they should be written in CapWords as per Solidity style guide,

2. How can we emit events?

Events are emitted by using them in the body of a function. An example below:

contract C {
    event EventSendCoin(address indexed sender, address indexed receiver, uint256 amount);

    function sendCoin(address receiver, uint amount) returns (bool sufficient) {
        // ...
        EventSendCoin(msg.sender, receiver, amount);
        return true;
    }
}
3. How and where do we listen for events?

Events can be accessed from an external application, using the RPC interface of an ETH client, such as a Dapp. Events cannot be accessed within a smart contract, not even the smart contracts that created them.

1 Like

#92
  1. How are events declared?
    contract Example {
    event TEST(
    address indexed _from,
    bytes32 indexed _id,
    uint _value
    );
  2. How can we emit events?
    Using ’emit’ followed by the name of the event and the arguments.
    Emit Example(msg.sender, _id, msg.value);
  3. How and where do we listen for events?
    By using a callback function in the Javascpript, which will display the event when its triggered.
1 Like

#93

1. How are events declared?
Events can be declared by using event eventName(code);
2. How can we emit events?
Events can be emitted by using emit eventName(args);
3. How and where do we listen for events?
Events are listened for in the JavaScript API.

1 Like

#94
  1. Events are declared in the contract as follows:

event EvenName(); // up to 3 “indexed” parameters, e.g.:

event Deposit (
  address indexed _from,
  bytes32 indexed _id,
  uint _value
);
  1. emit en event inside a function, as follows:
    emit EventName() // with the parameters, if any, e.g.:
    emit Deposit(msg.sender, _id, msg.value);

  2. We listen to events e.g. in the client side, e.g. using the javascript API, subscribing to an event and then watch changes, or using a callback directly

1 Like

#95
  1. How are events declared? Events are declared within the event statement. You can declare them with specific modifiers such as ‘anonymous’ this particular declaration removes the hash of the signature of the event from the log, therefore preventing searches for it by name.

  2. How can we emit events? By using the emit statement.

  3. How and where do we listen for events? Applications can subscribe and listen to events through the RPC interface of an Ethereum client.

0 Likes