Reading assignment - Solidity Events

  1. How are events declared?
    With the keyword event.
  2. How can we emit events?
    Events are emitted using emit, followed by the name of the event and the arguments.
  3. How and where do we listen for events?
    We can listen to them in our Javascript.
1 Like
  1. We declare events in a smart contract with the ā€˜event’ keyword.
  2. An event is emitted within a function by calling the declared event function using keyword ā€˜emit’, followed by the name of the event and the arguments (if any) in parentheses.
    3.We can listen for events through the RPC interface of an Ethereum client. It is done using callback function.
1 Like
  1. How are events declared?
    With the ā€œeventā€ key word followed by the name of the event and argument. example:
    Contract SimpleAuction {
    event HighestBid (address bidder, uint amount);

  2. How can we emit events?;
    Events are emitted by using the ā€œemitā€ key word. example
    function bid() public payable {
    emit HighestBid ( msg.sender, msg.value);

  3. How and where do we listen for events?
    Events are inheritable members of contracts. When you call them, they cause the arguments to be stored in the transaction’s log - a special data structure in the blockchain.
    You can add the attribute indexed to up to three parameters which adds them to a special data structure known as ā€œtopicsā€ instead of the data part of the log.
    Applications can subscribe and listen to events through the RPC (Remote Procedure Call ?) interface of an Ethereum client.

1 Like
  1. Events are declared with the ā€œeventā€. then give the argument.

  2. EventName (argument1, argument2);

  3. The Dapp front end will be listening for the event using the JavaScript API.

1 Like

Solidity Events - Reading Assignment

Events are ihneritable members of contracts which allows us to provide JavaScript callbacks in a user interface.
  1. How are events declared?
event myEventName (Parameters);
  1. How can we emit events?
myEventName(Parameter Values);
  1. How and where do we listen for events?
    In JavaScript
let contractName = ..
let eventName = contractName.myEventName();
eventName.watch(function(error, result){
 Statement:
}
  • through a RPC interface of an Ethereum client
1 Like
  1. How are events declared?
contract ClientReceipt {
    event Deposit(
        address indexed _from,
        bytes32 indexed _id,
        uint _value
    );
  1. How can we emit events?

Events are emitted using emit, followed by the name of the event and the arguments (if any) in parentheses. Any such invocation (even deeply nested) can be detected from the JavaScript API by filtering for Deposit.

function deposit(bytes32 _id) public payable {
        emit Deposit(msg.sender, _id, msg.value);
    }
  1. How and where do we listen for events?

The use in the JavaScript API is as follows:

var abi = /* abi as generated by the compiler */;
var ClientReceipt = web3.eth.contract(abi);
var clientReceipt = ClientReceipt.at("0x1234...ab67" /* address */);

var event = clientReceipt.Deposit();

// watch for changes
event.watch(function(error, result){
    // result contains non-indexed arguments and topics
    // given to the `Deposit` call.
    if (!error)
        console.log(result);
});


// 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?
    With the keyword event myEventName(…);

  2. How can we emit events?
    myEventName(…);

  3. How and where do we listen for events?
    By calling Javascript Callbacks

1 Like
  1. Events are declared by using the events keyword followed by the name of the event.
event addThisToLog(string loggedData, address ofOwner);
  1. We can emit events by adding the emit keyword within the function we want to trigger the event to be emitted.
function emitSomething(string _msg) public {
    emit addThisToLog(_msg, msg.sender);
}
  1. Events are added to the Log, which is a section within each block of the Ethereum blockchain. Once added, they are stored on the blockchain and can be used as receipt confirmations in transactions for users. The front end of a Dapp can listen for events to enhance the UI and improve UX. Additionally, the indexed attribute can be used to modify the arguments of an event so they are added to the Topics data structure of the block. This makes the argument searchable so it’s easier to filter through a series of blocks when searching for specific events.
1 Like
  1. Events are declared as structures with event keyword
  2. With key word emit EventName(parameters)
  3. Gettin event by name let event = ContractName.EventName(), and then event.watch(someAnonFunc(){})
1 Like
  1. How are events declared?

Within a contract as follows :

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

  1. How can we emit events?

function deposit(bytes32 _id) public payable {
// Events are emitted using emit, followed by
// the name of the event and the arguments
// (if any) in parentheses. Any such invocation
// (even deeply nested) can be detected from
// the JavaScript API by filtering for Deposit.
emit Deposit(msg.sender, _id, msg.value);

  1. How and where do we listen for events?

Solidity events give an abstraction on top of the EVM’s (Ethereum Virtual Machine) logging functionality. Applications can subscribe and listen to these events through the RPC (Remote Procedure Call) interface of an Ethereum client.

1 Like
  • How are events declared?
event myEvent (string par1, bool par2);
  • How can we emit events?
emit myEvent (newstring, newbool);
  • How and where do we listen for events?
    apps that interact via API with our contract and JavaScript callbacks can be used to listen to events.
1 Like

How are events declared?
Events are declared with the keyword ā€œEventeā€ in front of the event name.
For example: event transferlog ()

How can we broadcast events?
Inside the function that we need to register the log, we call the event with the word ā€œemitā€.
For example: emit transferlog ()

How and where do we listen to the events?
We listen to them in the Dapp interface or web3 application through javascript
Por ejemplo: clientReceipt.transferlog()

1 Like

Small typo it’s event and not Evente :wink:

2 Likes

Thanks @gabba it was a mistake to write

  1. With an ā€œeventā€ keyword.
  2. Calling it in a function.
  3. Via EVM log.

1. How are the events declared?

Events in Solidity are declared by using the event keyword which stores them into a special data structure in the blockchain.

2. How can we emit events?

Events are emitted using ā€œemitā€ which are followed by the name of the event and the arguments in parentheses.

3. How and where do we listen for events?

Applications can subscribe and listen to events we use RPC interface of an Etherium client.

1 Like
  1. How are events declared?
    Events are declared by using the keyword event in the smart contract.

  2. How can we emit events?
    Emits are declared by using the keyword emit in the smart contract.

  3. How and where do we listen for events?
    Applications can subscribe and listen to these events through the RPC interface of an Ethereum client. In this case you can use a JavaScript API. However t is also possible to access the low-level interface to the logging mechanism via various log functions in solidity.

1 Like

EVENTS.

How events are declared.

Events are declared in a smart contract with the event keyword.

How we can emit the events.

They are emitted by activating the event in a function.

How and where do we declare events.

A callback occurs in the javascript API, this allows us to listen for events

1 Like
  1. How are events declared?

var event = function();

or

event function();

  1. How can we emit events?

event function ();

emit function(args);

  1. How and where do we listen for events?

in front end code with javascript using:

event.watch(function(error, result){
// result contains non-indexed arguments and topics
// given to the Deposit call.
if (!error)
console.log(result);
});

1 Like
  1. By using the event keyword and writing the function.
  2. By using the emit keyword or calling the event function.
  3. By using a javascript API and also querying event logs.
1 Like