/
Events in Solidity B. Ramamurthy Events in Solidity B. Ramamurthy

Events in Solidity B. Ramamurthy - PowerPoint Presentation

unita
unita . @unita
Follow
67 views
Uploaded On 2023-05-22

Events in Solidity B. Ramamurthy - PPT Presentation

  Learning outcomes Explain the concept of events defining an event and pushing an event to any subscribed listeners Illustrate the events using the blind auction example Logging Events for ID: 999017

events event blind log event events log blind args votingcompleted var auction push function logs result singulartext auctionended emit

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Events in Solidity B. Ramamurthy" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. Events in SolidityB. Ramamurthy 

2. Learning outcomesExplain the concept of events: defining an event and pushing an event to any subscribed listeners.Illustrate the events using the blind auction example.Logging Events for

3. event nameOfEvent( parameters);Example:event votingCompleted(); // for ballotEvent definition and invocation//event definitionevent votingCompleted();//event invocationemit votingCompleted();

4. Blind Auctionevent AuctionEnded(address winner, uint highestBid);emit AuctionEnded(highestBidder, highestBid);Definitionpushing an event

5. Invoking an event is by the name of the event and any parameters.In the function Vote when the stage changes to Done, we indicate that by invoking “votingCompleted” event.emit votingCompleted();In the case of Ballot, we will push this event at the end of the voting period.In the case of Blind Auction, we push the event when the auction ends?Is it useful to push events for every phase? Let’s do that.Event invocation

6. Event LoggingAn event is pushed as opposed to regular function call that is invoked or pulled to get action performed.Typically event feature is used to indicate to a client application (user interface or a transaction monitor) that a significant milestone has been reached.These applications can listen to the events pushed to::Track transactionsReceive results through arguments of the eventsInitiate a pull request to receive information from the smart contract.Event handlers are written in app.js and they get the logs from the block header.

7. Let’s explore it first in RemixFor Blind auction, we will do these:Define an event for AuctionEnded, and push it in auctionEnd function.Then observe its operation in Remix consoleLets add one more event:event RevealPhase(bytes32 x);if (x == Phase.Reveal) emit RevealPhase ("reveal phase");

8. Where are these events stored? They are “logged” in the logs of the block header.if(result.receipt.status != '0x01') alert("Transfer failed"); for (var i = 0; i < result.logs.length; i++) { var log = result.logs[i]; var singularText = "coins were"; if(log.args.amount == 1){ singularText = "coin was"; } // Look for the event Sent // Notification if (log.event == "Sent") { var text = 'Coin transfer: ' + log.args.amount + " " +singularText + ' sent from ' + log.args.from + ' to ' + log.args.to + '.'; jQuery('#showmessage_text').html(text); jQuery('#show_event').animate({'right':'10px'}); setTimeout(function(){jQuery('#show_event').animate({'right':'-410px'},500)}, 15000); break; } }

9. SummaryLets add events to Blind AuctionFor announcing the phases : Bidding and RevealLets now examine the ASK.sol