Skip to content

codewithgabriel/voting-system-using-blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Voting DApp — Installation Guide

This guide will walk you through setting up and running the Voting DApp on your local machine, even if you’re new to blockchain development.


Prerequisites

Before starting, make sure you have the following installed:

  1. Node.js (Download from https://nodejs.org)

    • After installation, check with:
      node -v
      npm -v
  2. MetaMask Wallet


Step 1: Install Ganache CLI

Ganache provides a personal Ethereum blockchain for testing smart contracts.

Run this command in your terminal:

npm install -g ganache-cli

To start Ganache:

ganache-cli

Keep this terminal open — it will display several Ethereum accounts with private keys.
You’ll use one of these accounts later.


Step 2: Compile and Deploy the Smart Contract

  1. Open another terminal window (keep Ganache running).
  2. Navigate to the project directory (after unzipping the project):
    cd voting-contract
  3. Install Truffle, the development framework for Ethereum:
    npm install -g truffle
  4. Compile the smart contracts:
    truffle compile
  5. Deploy the contracts to your local blockchain (Ganache):
    truffle migrate

When deployment finishes, you’ll see an output that includes a contract address.
Copy this address — you’ll need it for the frontend setup.


Step 3: Update the Contract Address in the Frontend

  1. Open the file:
    voting-system/src/hooks/useVotingContract.js
    
  2. On line 8, find the placeholder address:
    "0xC1465a3908566d19A5aDBFd6549BcE1ec3dB783B"
    
  3. Replace it with the new contract address you copied from the Truffle migration output.
  4. Save the file.

Step 4: Run the Frontend (React App)

  1. From the voting-contract folder, move back to the main project directory:
    cd ..
  2. Navigate to the frontend folder:
    cd voting-system
  3. Install the required dependencies:
    npm install
  4. Start the development server:
    npm run dev

Once it starts, open your browser and visit the local URL shown (usually http://localhost:5173 or http://localhost:3000).


Step 5: Connect MetaMask

  1. Open MetaMask in your browser.
  2. Click your profile icon → Networks → Add Network → Localhost 8545
  3. Import one of the private keys from Ganache to get test ETH.
  4. Refresh the DApp page and connect MetaMask when prompted.

You’re All Set!

You now have:

  • A local Ethereum blockchain running via Ganache
  • Smart contracts deployed with Truffle
  • A frontend connected to your contract via MetaMask

You can start testing your decentralized voting system right away 🎉

About

A blockchain based voting system built using solidity programming language and thirdwebjs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published