Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hardhat Voting System

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.

Features

  • 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

Tech Stack

  • Solidity — smart contract language
  • Hardhat — Ethereum development environment
  • JavaScript — deployment & test scripts
  • Ethers.js — blockchain interaction library

Project Structure

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.)

Prerequisites

  • 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

Installation

Clone the repository and install dependencies:

git clone https://github.com/aadyatalreja/hardhat-voting-system.git
cd hardhat-voting-system
npm install

Configuration

Create 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_url

Never commit your .env file or expose your private key. Make sure .env is listed in .gitignore.

Usage

Compile the contracts

npx hardhat compile

Run the test suite

npx hardhat test

Start a local blockchain node

npx hardhat node

Deploy to localhost

In a separate terminal (with the local node running):

npx hardhat run scripts/deploy.js --network localhost

Deploy to a testnet

Make sure your hardhat.config.js includes the target network configuration, then run:

npx hardhat run scripts/deploy.js --network <network-name>

How It Works

The voting contract typically follows this flow:

  1. The contract is deployed with an initial set of candidates/proposals.
  2. Each eligible address can cast one vote for a candidate.
  3. The contract tracks vote counts and prevents an address from voting more than once.
  4. 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.)

Testing

Tests are located in the test/ directory and can be run with:

npx hardhat test

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request with improvements, bug fixes, or new features.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/your-feature)
  3. Commit your changes
  4. Push to the branch and open a pull request

License

This project is licensed under the MIT License.

About

A decentralized blockchain-based voting system built with Hardhat and Solidity, enabling secure, transparent, and tamper-resistant elections through Ethereum smart contracts with automated deployment and testing workflows.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages