The Web3.0 Voting System is a team assignment designed for the "Blockchain Technologies and Applications" course, offered in the 8th semester of the 2023-2024 academic year at the University of Piraeus, Department of Informatics. This decentralized application (DApp) leverages blockchain technology to create a transparent, secure, and immutable voting process. Built using Solidity and deployed via the Remix IDE on the Ethereum blockchain, the system allows users to create polls, cast votes, and view results while ensuring that all votes are tamper-proof and each user can vote only once per poll.
- Institution: University of Piraeus
- Department: Department of Informatics
- Course: Blockchain Technologies and Applications (2024)
- Semester: 8th
- Solidity: For writing smart contracts.
- Ethereum Blockchain: For deploying and managing the voting system.
- Remix IDE: For developing, deploying, and testing smart contracts on Ethereum.
- Metamask: For interacting with the blockchain and managing transactions.
The Web3.0 Voting System supports the following features through its smart contract:
-
Create a New Poll
- Users can create a new poll with a yes/no question.
- Each poll is added to the blockchain and is accessible to registered users.
-
Cast a Vote
- Users can cast a "Yes" or "No" vote on an active poll.
- The system ensures that each user can vote only once per poll, and their vote is permanently recorded on the blockchain.
-
Close a Poll
- The poll creator or a designated user can close a poll manually, preventing any further votes from being cast.
-
View Poll Results
- Users can view the total number of "Yes" and "No" votes for any closed poll, with results stored immutably on the blockchain.
The smart contract is written in Solidity and consists of several key components:
-
Struct Poll: Defines the structure of a poll, including:
string question
: The poll question.bool isClosed
: Indicates if the poll is open or closed.mapping(address => bool) hasVoted
: Tracks which addresses have voted.uint yesVotes
: Total number of "Yes" votes.uint noVotes
: Total number of "No" votes.
-
Key Functions:
createNewPoll(string memory _question)
: Allows users to create a new poll with the specified question.castVote(uint pollIndex, bool vote)
: Enables users to cast a "Yes" (true) or "No" (false) vote for a specific poll.closePoll(uint pollIndex)
: Closes a poll, preventing further voting.showPollResults(uint pollIndex)
: Displays the results of a closed poll.
-
Creating a Poll
A user creates a new poll by calling the
createNewPoll
function with the desired question:createNewPoll("Should we implement feature X?")
-
Voting on a Poll
Users can cast their vote by calling the
castVote
function and passing the poll index and their vote:castVote(0, true); // Vote "Yes" on poll 0 castVote(0, false); // Vote "No" on poll 0
-
Closing a Poll
Once the voting period is over, the poll can be closed using the
closePoll
function:closePoll(0); // Close poll 0
-
Viewing Poll Results
To view the results of a poll, the
showPollResults
function is called, displaying the total number of "Yes" and "No" votes:showPollResults(0);
This function returns the number of votes for and against the poll's question.
-
Clone the repository:
git clone https://github.com/thkox/web3.0-voting-system.git
-
Deploy the Smart Contract:
- Open Remix IDE in your browser: Remix IDE.
- Create a new Solidity file and paste the smart contract code.
- Compile the contract using the Solidity compiler.
- Deploy the contract on a test Ethereum network (e.g., Ropsten, using Metamask or Ganache).
-
Interact with the Contract:
- Use the Remix console to call the contract’s functions (create polls, cast votes, close polls, etc.).
- Ensure you have sufficient test Ether in your Metamask wallet to cover gas fees when interacting with the blockchain.
- Full project details can be found in the Project-documentation.pdf.
Apostolis Siampanis |
Theodore Koxanoglou |
This project is licensed under the MIT License - see the LICENSE file for details.