I built a Voting System #4672
Replies: 4 comments 6 replies
-
|
Great job @MartinsAloysius |
Beta Was this translation helpful? Give feedback.
-
|
Nice and clean work 👏 @MartinsAloysius :) |
Beta Was this translation helpful? Give feedback.
-
|
Hey @MartinsAloysius, dude, I just stumbled across your VotingSystem repo, and holy cow, I’m absolutely blown away! Seriously, you’ve built something that’s not just a cool learning project but a legit stepping stone into the wild world of Solidity—props to you for dropping that on GitHub! The way you’ve nailed down structs, mappings, modifiers, and events in such a clean setup with owner controls and that slick one-vote-per-address rule? Mind-blowing for a portfolio piece, man! But hold onto your seat, because I’ve got some next-level upgrades to throw your way that’ll make your jaw drop and turn this into a beast of a contract. I’ve been digging into the Cyfrin Foundry course (that monster Patrick Collins put together) and flipping through "Mastering Ethereum" by Andreas Antonopoulos and Gavin Wood—yep, the bee-covered bible of smart contracts! Here’s what I think you should blast into this project to shock the web3 world:
Check this out—I’ve refactored your contract with these mind-blowing tweaks. Test it like crazy, but here it is: // SPDX-License-Identifier: License @MartinsAloysius will put in his repo `https://github.com/MartinsAloysius/VotingSystem`
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/access/Ownable.sol";
contract VotingSystem is Ownable {
bool public votingActive;
struct Candidate {
uint256 id;
string name;
uint256 voteCount;
}
mapping(uint256 => Candidate) public candidates;
mapping(address => bool) public hasVoted;
uint256 public candidateCount;
uint256 public totalVotes;
event CandidateAdded(uint256 id, string name);
event VoteCast(address voter, uint256 candidateId);
event VotingStarted();
event VotingEnded();
modifier votingIsActive() {
require(votingActive, "Voting not active");
_;
}
modifier beforeVoting() {
require(!votingActive, "Voting already started");
_;
}
function addCandidate(string memory _name) public onlyOwner beforeVoting {
candidateCount++;
candidates[candidateCount] = Candidate(candidateCount, _name, 0);
emit CandidateAdded(candidateCount, _name);
}
function startVoting() public onlyOwner {
require(candidateCount > 0, "Add candidates first");
votingActive = true;
emit VotingStarted();
}
function endVoting() public onlyOwner {
votingActive = false;
emit VotingEnded();
}
function vote(uint256 _candidateId) public votingIsActive {
require(!hasVoted[msg.sender], "Already voted");
require(_candidateId > 0 && _candidateId <= candidateCount, "Invalid candidate");
hasVoted[msg.sender] = true;
candidates[_candidateId].voteCount++;
totalVotes++;
emit VoteCast(msg.sender, _candidateId);
}
function getCandidateVotes(uint256 _id) public view returns (uint256) {
require(_id > 0 && _id <= candidateCount, "Invalid candidate");
return candidates[_id].voteCount;
}
}This is next-level stuff, bro! Deploy it on Sepolia with Foundry and drop the address—let’s see it in action and get some live feedback. And hey, I’m pumped for your next project—hit me up on or X(@mirmohmmadluqman) if you’re down to collab on something insane, like mashing this with Solana for cross-chain voting (that ETS thesis from Federico Pomponii’s got some wild token ideas!). Keep crushing it, man. I have also a project but I am learning the skills to work for that, can you tell me your skills man, but skills related to web3. You’re about to blow the web3 community away! 🚀 |
Beta Was this translation helpful? Give feedback.
-
|
@MartinsAloysius here's a pro tip, have a LICENSE for you project/repo ! |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Hey guys, checkout this github repo to see the voting system I built. Do let me know what you think. Here is the link: https://github.com/MartinsAloysius/VotingSystem
Also, I'll be looking forward to meeting anyone who would love to join me in my next project. Dm me via telegram: @XTER_THY or via X: https://x.com/Xterthy_3
Beta Was this translation helpful? Give feedback.
All reactions