Skip to content

TusharB-07/voting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Voting System using Smart Contracts

A transparent, tamper-proof voting DApp using Solidity, Hardhat, and a simple HTML/JS frontend. This project demonstrates the core concepts of decentralized application development on the Ethereum blockchain.

Concepts Covered

  • Smart contracts for voting logic
  • Preventing double voting
  • Event logging for transparency
  • Owner-restricted functionalities

Technologies Used

  • Solidity: For writing the smart contract.
  • Hardhat: For Ethereum development environment, testing, and deployment.
  • Ethers.js: For interacting with the Ethereum blockchain from the frontend.
  • HTML/JavaScript: For the frontend application.
  • MetaMask: As the wallet to connect to the DApp.

Project Structure

.
├── contracts/
│   └── Voting.sol
├── scripts/
│   └── deploy.js
├── test/
│   └── voting-test.js
├── frontend/
│   ├── index.html
│   └── app.js
├── hardhat.config.js
└── package.json

How to Run This Project

Prerequisites

1. Clone & Install

Clone this repository and install the required dependencies.

git clone https://github.com/TusharB-07/voting.git
cd voting
npm install

2. Compile the Smart Contract

Compile the Voting.sol contract.

npx hardhat compile

After compiling, a new artifacts directory will be created. You will need the ABI from artifacts/contracts/Voting.sol/Voting.json.

3. Start the Local Blockchain

Run a local Hardhat blockchain node.

npx hardhat node

This will start a local Ethereum network and generate several accounts with test Ether. Keep this terminal window open.

4. Deploy the Smart Contract

In a new terminal window, deploy the contract to the local network.

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

Copy the deployed contract address from the terminal output.

5. Configure the Frontend

  1. Open frontend/app.js.
  2. Paste the deployed contract address into the contractAddress variable.
  3. Copy the ABI from artifacts/contracts/Voting.sol/Voting.json and paste it into the contractABI variable.

6. Run the Frontend

Serve the frontend directory using a simple web server.

npx http-server frontend

7. Use the DApp

  1. Open your browser and navigate to http://127.0.0.1:8080.
  2. Configure MetaMask:
    • Add a new network with the following details:
      • Network Name: Local Hardhat
      • New RPC URL: http://127.0.0.1:8545
      • Chain ID: 31337
    • Import an account into MetaMask using one of the private keys provided by the npx hardhat node command. The first account is the contract owner.
  3. Connect MetaMask to the DApp and start interacting with it.

Cheat Sheet

  • Run local chain: npx hardhat node
  • Deploy contract: npx hardhat run scripts/deploy.js --network localhost
  • Serve frontend: npx http-server frontend
  • Admin actions: addCandidate, registerVoter, setPhase
  • Voter actions: vote (once, only in the Voting phase)

Security & Improvements

  • Restrict admin actions via a more robust system like a DAO.
  • Optimize gas usage.
  • Add TheGraph for real-time off-chain data indexing.
  • Implement commit-reveal or zk-SNARKs for private voting.
  • Perform security audits before any mainnet deployment.

Next Steps

  • Add token-weighted voting.
  • Upgrade the frontend to a modern framework like React or Vue.

About

A transparent, tamper-proof voting DApp using Solidity, Hardhat, and a simple HTML/JS frontend. This project demonstrates the core concepts of decentralized application development on the Ethereum blockchain.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors