A decentralized voting application built on the Ethereum blockchain that allows for secure, transparent, and tamper-proof voting campaigns.
This project implements a voting system on the blockchain with the following features:
- Create and manage voting campaigns
- Add candidates to campaigns
- Set campaign duration and start times
- Vote securely with prevention of double voting
- View real-time voting results and status
The smart contract architecture consists of:
- CampaignFactory: Contract that creates and manages multiple voting campaigns
- Campaign: Individual voting campaign contract with candidate management and voting functionality
- Node.js (v14+ recommended)
- npm (usually comes with Node.js)
- Ganache - A personal blockchain for Ethereum development
Clone the repository and install the required npm packages:
git clone https://github.com/DepartmentX/Solidity-Team.git
cd Solidity-Team
npm install- Download and install Ganache from https://trufflesuite.com/ganache/
- Launch Ganache and quickstart with ethereum.
- Once Ganache is running, it will provide you with:
- An RPC server URL (typically
http://127.0.0.1:7545) - A list of accounts with their private keys
- An RPC server URL (typically
- Copy one of the private keys from Ganache (click the key icon next to any account)
- Create or modify the
.envfile in the project root:
API_URL="http://127.0.0.1:7545"
PRIVATE_KEY="<your-private-key-from-ganache>"
Make sure to replace <your-private-key-from-ganache> with the actual private key you copied.
Compile the Solidity contracts using Hardhat:
npx hardhat compileDeploy the contracts to your local Ganache blockchain:
npx hardhat run --network ganache scripts/deploy.jsAfter successful deployment, you'll see a message with the deployed contract address:
✅ CampaignFactory deployed at: 0x...
Save this contract address as you'll need it for frontend integration or interacting with the contract.
The deployed contracts allow you to:
- Create new voting campaigns
- Add candidates to campaigns
- Vote for candidates
- View voting results
You can interact with the contracts through:
- A frontend application connected to the contracts
- Hardhat console
- Remix IDE by importing the deployed contract address
The project includes tests for the smart contracts. Run tests with:
npx hardhat test- Only the campaign owner can add new candidates
- Voters can only vote once per campaign
- Voting is only allowed during the campaign's active period
- Campaign data is stored transparently on the blockchain
This project is licensed under the ISC License.