A decentralized voting application built with Hardhat, Solidity, and JavaScript. This project demonstrates how to write, test, and deploy a smart contract that allows users to cast votes on the Ethereum blockchain in a secure, transparent, and tamper-proof way.
- On-chain voting logic written in Solidity
- Prevents double voting per address
- Hardhat development environment for compiling, testing, and deploying
- Automated test suite for contract behavior
- Deployment scripts for local and test networks
- Solidity — smart contract language
- Hardhat — Ethereum development environment
- JavaScript — deployment & test scripts
- Ethers.js — blockchain interaction library
hardhat-voting-system/
├── contracts/ # Solidity smart contracts
├── scripts/ # Deployment scripts
├── test/ # Contract test suite
├── artifacts/ # Compiled contract artifacts (auto-generated)
├── cache/ # Hardhat cache (auto-generated)
├── hardhat.config.js
├── package.json
└── .env # Environment variables (RPC URL, private key, etc.)
- Node.js (v16 or later recommended)
- npm
- A wallet with testnet ETH if deploying to a live testnet (e.g. Sepolia)
- An RPC provider URL (e.g. from Infura or Alchemy) if deploying beyond localhost
Clone the repository and install dependencies:
git clone https://github.com/aadyatalreja/hardhat-voting-system.git
cd hardhat-voting-system
npm installCreate a .env file in the project root (if not already present) with the following variables:
PRIVATE_KEY=your_wallet_private_key
RPC_URL=your_rpc_provider_urlNever commit your
.envfile or expose your private key. Make sure.envis listed in.gitignore.
npx hardhat compilenpx hardhat testnpx hardhat nodeIn a separate terminal (with the local node running):
npx hardhat run scripts/deploy.js --network localhostMake sure your hardhat.config.js includes the target network configuration, then run:
npx hardhat run scripts/deploy.js --network <network-name>The voting contract typically follows this flow:
- The contract is deployed with an initial set of candidates/proposals.
- Each eligible address can cast one vote for a candidate.
- The contract tracks vote counts and prevents an address from voting more than once.
- Vote tallies can be read at any time via public view functions.
(Refer to the contract source in contracts/ for the exact function names and logic used in this implementation.)
Tests are located in the test/ directory and can be run with:
npx hardhat testContributions are welcome! Feel free to open an issue or submit a pull request with improvements, bug fixes, or new features.
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature) - Commit your changes
- Push to the branch and open a pull request
This project is licensed under the MIT License.