Skip to content

Mayank534/Mastering_web3.0

Repository files navigation

Final Assignment of Summer Project 'Mastering Web 3.0'

In this assignment we were asked to create a DApp for conducting Student Gymkhana Elections at our campus. Mayank and Shivansh have collaborated together to create the solution of this final assignment.

The final website has been hosted on this link: exquisite-fenglisu-cbf03d.netlify.app. In any case , if this link doesn't work one can run the index.html file itself from the repo use the website.

The following describes how this submitted workspace works:

Smart Contract:

The smart contract has been written in solidity and has the following functionalities:

  • It contains of class Candidate whch is used to add identities of candidates that are going to contest for elections. They have attributes of name and totalVotes .

  • It also contains class Voters that contain information about voters and have attributes registered, voted, candidateVotes.

    • registered is a bool function used to kep track of whether the voter is registered or not.
    • voted is a bool function to keep track of whether the voter has already voted or not.
    • candidateVotes is an array which takes indexes of three candidates as an input and assign 5,3 and 1 votes to to first,second and third entry repectively.
  • Next I have created a constructer which is called by owner of contract to register the candidates

  • Then there is function registerVoter which is called by voter to register himself to enable him to vote. It forsees that the caller is not already registered.

  • Then there is castVote function which gives voter a option to choose 3 candidates from given options and give them a priority order 1,2 and 3 which are given 5,3 and 1 votes respectively.

  • Then there is a function winningCandidate which on calling calculates to total votes and returns the index of winning candidate.

  • The last function is winningCandidateName which reveals the name of winning candidate.

Front End

The file starts from index.html where one gets the GYMKHANA voting page

You need a metamask account to connect with it.

click on the connect to metamask account and the metamask extention will pop up alt text

once you have connected it will display a command promt saying you are connected alt text

Now you will be directed to the voting page.

alt text

The voting page consists of 4 candidates(can be changed) wherein the images are responsive. You have to enter the indexes of the candidates you want to vote in order According to our contract the first index will have 5 points second 3 and third 1. You will not be able to enter if the index excess the number of candidates.

alt text

When entered the indexes, the user can register themselves as votes, this will allow the voter to vote only once and the account should be verified in order to vote. The prompts are added in the election.sol file.

alt text when voted the standing of the candidates will be refreshed and the name of the candidates and the total number of vote will be displayed

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published