Replies: 1 comment
-
This is amazing @G-r-ay thanks for this contribution. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone, I'm gray a data scientist looking into the smart contract world. With a course of about 27 or 28 hours, I like to test out what I had learnt in the form of challenge project at intervals between a bunch of lessons, so here is my project description for LESSON 1-4
Project Challenge: Voting Smart Contract
Your task is to develop a voting smart contract using Solidity. The smart contract should allow users to vote for candidates in an election. Each voter can only vote once.
Tasks:
Implement a function named
Vote
that allows voters to cast their votes. The function should take two parameters:The voter's name, and the name of the candidate the voter is voting for.Add a mapping named
VotingMap
(or whatever naming convention you choose) to store the mapping of voters to their chosen candidates. The mapping should associate each voter's name with the name of the candidate they voted for.Create private variables to store the candidates' information, such as their names and any other relevant details.
Develop logic(if and else statement) inside the
Vote
function to handle the voting process. Update the necessary variables or mappings to record the vote for the selected candidate by the voter.Implement functions to retrieve the vote count for each candidate. These functions should take the candidate's name as a parameter and return the corresponding vote count.
Create a function named
hasVoted
to check whether a voter has already cast their vote. This function should take a parametervoter
and return abool
value indicating whether the voter has voted or not.Implement a modifier named
onlyValidCandidate
to ensure that only valid candidate names can be voted for. Apply this modifier to theVote
function.Create a function named
getCandidateForVoter
that takes a parametervoter
(type:string
) and returns the name of the candidate (type:string
) that the voter voted for.Good luck with your project! This project may require a little bit of research to use logic statements, but being able to read the docs also counts as a developer skill👍. My solution will be on my github
(P.S the code doesn't have to pushed to a testnet, it can done on remix )
Beta Was this translation helpful? Give feedback.
All reactions