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.
Before starting, make sure you have the following installed:
-
Node.js (Download from https://nodejs.org)
- After installation, check with:
node -v npm -v
- After installation, check with:
-
MetaMask Wallet
- Install the MetaMask browser extension: https://metamask.io/download
Ganache provides a personal Ethereum blockchain for testing smart contracts.
Run this command in your terminal:
npm install -g ganache-cliTo start Ganache:
ganache-cliKeep this terminal open — it will display several Ethereum accounts with private keys.
You’ll use one of these accounts later.
- Open another terminal window (keep Ganache running).
- Navigate to the project directory (after unzipping the project):
cd voting-contract - Install Truffle, the development framework for Ethereum:
npm install -g truffle
- Compile the smart contracts:
truffle compile
- 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.
- Open the file:
voting-system/src/hooks/useVotingContract.js - On line 8, find the placeholder address:
"0xC1465a3908566d19A5aDBFd6549BcE1ec3dB783B" - Replace it with the new contract address you copied from the Truffle migration output.
- Save the file.
- From the
voting-contractfolder, move back to the main project directory:cd .. - Navigate to the frontend folder:
cd voting-system - Install the required dependencies:
npm install
- 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).
- Open MetaMask in your browser.
- Click your profile icon → Networks → Add Network → Localhost 8545
- Import one of the private keys from Ganache to get test ETH.
- Refresh the DApp page and connect MetaMask when prompted.
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 🎉