Loading...
Hello, World!
In this smart book we are gonna see one project based on the dao appliactions .
So there are basically lot's of projects avialable on the internet based on the DAO application . One of them is Voting application that today we are going to see and learn in this blog .
In that application we have many function like vote particular participant , see the address of each participant , count the vote , owner address .
Let's look on the smart contarct code and discussed various function and working .
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract vote{
string public winner;
address public participant1 = 0xF6C486B8A4e67b8eff4d5045C804E9be4ed39FF9;
address public participant2 = 0xBBDb2A08711D7b2b9c15318E77B6e026eD8fA278;
mapping(address=>uint) user;
mapping(address=>bool) chek;
address public owner;
constructor(){
owner = msg.sender;
}
modifier onlyonwner(){
require(msg.sender == owner,"You are not allowed to declare the result");
_;
}
function participant1_vote() public {
require(msg.sender !=participant1,"You can not vote to yourself");
require(chek[msg.sender]!=true,"You have already voted");
user[participant1]++;
chek[msg.sender] = true;
}
function participant2_vote() public {
require(msg.sender !=participant2,"You can not vote to yourself");
require(chek[msg.sender]!=true,"You have already voted");
user[participant2]+=1;
chek[msg.sender] = true;
}
function pati1_cnt_VOTE() view public returns(uint){
return user[participant1];
}
function pati2_cnt_VOTE() view public returns(uint){
return user[participant2];
}
function declare_winner() public onlyonwner {
if(user[participant1]>user[participant2]){
winner = "Candidate 1 is winner";
// winner = _winner;
}
else if(user[participant1]==user[participant2]){
winner = "Draw";
// winner = _winner;
}
else{
winner = "Candidate 2 is winner";
// winner = _winner;
}
}
}
There is one modifier which is onlyowner that is used to check whether that particular function is called by the owner or not , if not then this will revert the error message .
Which make's this an application of the DAO as the decalre winner is only called by the owner .
If u want to make the frontend part for this appllication then go through the below link provided.
1 . Source code
2 . Video tutorial .