A decentralized voting application built on Rootstock (RSK), allowing users to create secure polls or elections and vote using RSK tokens. The application ensures transparency and immutability of votes on the blockchain, empowering users to participate in decentralized decision-making.
- Add or remove proposals within a voting session.
- Cast votes and remove votes for proposals.
- View proposal details, including vote counts.
- Easily track votes by users per proposal.
Follow these steps to set up the project on your local machine:
- Node.js (v14 or later)
- Hardhat
- MetaMask browser extension
- Git installed on your machine
- An account on RSK Testnet Faucet to get test tokens
Compiling and deploying the contract is not required, as the contract as already been deployed on the Rootstock Testnet
-
Clone the repository:
git clone git@github.com:Pulsator01/Decentralised-Voting-Application.git cd Decentralised-Voting-Application
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory and add the following:PRIVATE_KEY=<your_private_key> RSK_TESTNET_URL=https://public-node.testnet.rsk.co
Replace
<your_private_key>
with your RSK testnet account private key. -
Compile the smart contracts:
npx hardhat compile
-
Deploy the smart contract to the RSK Testnet:
npx hardhat run scripts/deploy.js --network testnet
-
Run the frontend: Navigate to the frontend folder and run the dev script
cd voting-dapp-frontend npm install npm run dev
Open your browser and navigate to
http://localhost:3000
.
To interact with the smart contract through the frontend:
- Connect your MetaMask wallet to the RSK Testnet.
- Get test RSK tokens from the RSK Testnet Faucet.
- Deploy the contract as mentioned in the installation steps.
- Start creating sessions and casting votes!
- Add Proposals: Add proposals to a session.
- Vote: Cast votes on the proposals.
- Remove Votes: Remove votes if needed.
- View Proposals and Votes: Check the status of the proposals and votes at any time.
The Voting
smart contract includes the following methods:
Creates a new voting session. Only the user who creates the session can add or remove proposals.
Adds a proposal to a specific session. Only the session creator can add proposals.
- Parameters:
sessionId
: The ID of the session.name
: The name of the proposal.
Removes a proposal from a specific session. Only the session creator can remove proposals.
- Parameters:
sessionId
: The ID of the session.proposalIndex
: The index of the proposal to remove.
Allows users to cast votes for a proposal in a session.
- Parameters:
sessionId
: The ID of the session.proposalIndex
: The index of the proposal.numberOfVotes
: The number of votes to cast.
Allows users to remove their votes from a proposal in a session.
- Parameters:
sessionId
: The ID of the session.proposalIndex
: The index of the proposal.numberOfVotes
: The number of votes to remove.
Returns the number of proposals in a specific session.
- Parameters:
sessionId
: The ID of the session.
Returns the details of a specific proposal (name and vote count).
- Parameters:
sessionId
: The ID of the session.index
: The index of the proposal.
8. getVotesByUserForProposal(uint sessionId, address user, uint proposalIndex) public view returns (uint)
Returns the number of votes a user has cast for a specific proposal.
- Parameters:
sessionId
: The ID of the session.user
: The address of the user.proposalIndex
: The index of the proposal.
Contributions are welcome! Please fork this repository and open a pull request with your improvements.
This project is licensed under the MIT License - see the LICENSE file for details.