Smart Contract:
solidity
pragma solidity ^0.8.0;
contract Voting {
mapping(string => uint256) public votesReceived;
string[] public candidateList;
constructor(string[] memory candidates) {
candidateList = candidates;
}
function voteForCandidate(string memory candidate) public {
votesReceived[candidate] += 1;
}
function totalVotesFor(string memory candidate) public view returns (uint256) {
return votesReceived[candidate];
}
}
How It Works:
Store the candidate list
Records votes
Shows total votes
π‘ Try adding a feature to restrict voting to one per wallet addre