Ethereum Blockchain - Adding Event Watcher to Voting Functionality

Abhilash Nelson
A free video tutorial from Abhilash Nelson
Computer Engineering Master & Senior Programmer at Dubai
4.3 instructor rating • 20 courses • 36,208 students

Lecture description

Download the  Source Code from

https://1drv.ms/f/s!Ai9sVzhAVUlZgiYVRpNI8D-3hVMe

Learn more from the full course

Practical Blockchain & Smart Contracts : Ethereum & Solidity

A complete Practical Approach to Blockchain & Smart Contracts using Node.js - JavaScript & Solidity - Ethereum - web3.js

04:55:31 of on-demand video • Updated February 2020

  • A thorough understanding about blockchain technology. Create blockchain applications and Smart Contracts using Solidity language in Ethereum platform
English [Auto] In alone will come back to the final session on for interim based block chain and smart contract. And in this session we will have to deal with the problem with thought we had in the last session which is once we cast the board we have to manually refresh the pace to get this table back. So in this case we will add and water and even listen listener to listen for the worst casting event. And after that once it happens it has to refresh the page just like in previous session if you refresh the page prematurely of the page before the transaction actually happens you will not be getting that actual results you will be getting the orders. We had this problem last time. So once the transaction is completed it give you a pop up here and the transaction is complete and then we actually it will give the correct results. So all whatever we'll listen for the transaction to complete the transaction is complete. It will read on the page. So let's try that in our contract. We will also plan to extend it and here summer contract the corner store really define click on that and you can see here it's pasted code snippet just in here. This is also a declaration. So I will do it here. And here we are declaring an event called workbook event and instead when we have an unsigned indexed in digit called Understand 80 now we have the even declared. And so that will allow us to place this event in the function we want to trigger whenever this event happens. So we can have this even copy inside of our work function. So inside the word function we will have the even or even understand the trigger word event and this will trigger the event. So what happens is that we have or even heal. So once a person can still work after all the working functionality it will trigger this event. So after completing the whole thing it will trigger this event. The word event is declared here and that's in the modification it knows what contract we have to redeploy the contract on again. So let's stop this over just for a moment. And I in my Great Reset and it will redeploy the contract. So all the work and everything will be reset and the contract will be fully deployed. If we wanting to hear it it's ok. No problem. So our conduct is now online. And let's start. So once again you don't have to do this if you have to come on line of my house. And that's why I did it like this. And now we will go to the javascript file which is inside the subsidies. JS And just about that function we will have one more function whenever the function is called It will call. It will trigger our word even and when all this trigger occurs our after just to listen for that trigger and act accordingly. So that's why we are going to include this function here. So this function actually listen for events from the contract and just like in all our little functions we'll be getting an instance and in this line we will subscribe for this event. So we will have subscription for this. Even in this land and so on we subscribed we know today you in this card and we're not leaving this project we have this Kollek security. This is actually an index of the event from block to block letters. And what is interesting in here is this line that we will be rendering the page or and again when that event happens so whenever we're thinking is complete this line will be executing that is a page will be reloading and we have to call this listen for the events function inside our contract function. So just before the dawn Trantor We'll be calling this function or listen for events function will be calling. So it will happen like this. Is trying to work this or function will be executing. And the Certainly when will be trigger. And what I mean when we get the canvas and daily and the canvas and then it's actually passed to the function. It will pass to understand to the word but even so this event will be together and we have old web application listening for the sim and they've been called event. Because this isn't for when they subscribe to the word. So whenever that happens the water event does political and we have a four page reloader here to have the function interlaced when the contact is getting in place we will declare this function in the contract section and that you know it should work perfectly. Let's go to the page. So it should have already refreshed my notes we saved it. Now let's cost some more to Jerry Cast your vote and we're going to submit the plan section something. Yes that one section was confirmed. OK. So the transaction was confirmed and we got the word custom. And that's all we have successfully reloading the page or in the word discussed and without having to manually reload it. So I hope you have enjoyed the session and this is our last session in our calls. And also I have included the source code as their attachment for this course. So see you soon within the course. Have a great time. Bye bye.