Skip to content

Blockchain-based voting dApp, a final year university project

Notifications You must be signed in to change notification settings

s-takoor/mi-voting

Repository files navigation

🗳 MI-VOTING

TABLE OF CONTENTS

🚀 TL;DR

This documentation outlines the process of implementing the blockchain-based e-voting decentralized application (dApp) using Bun as the primary JavaScript runtime and toolkit. It covers setting up the development environment, deploying the smart contract on a local Hardhat Ethereum development environment, and implementing the Mi-Voting dApp.

🎬 DEMO

demo

🎯 OVERVIEW

This guide will walk you through the following key steps:

  1. Setting up the development environment.
  2. Deploying the smart contract on the local Hardhat Ethereum development environment.
  3. Implementing the Mi-Voting dApp.

🛠 TECHNOLOGIES AND TOOLS

Before we begin, ensure you have the following technologies and tools installed:

  • Bun: A fast JavaScript runtime & toolkit;
  • Hardhat: A development environment for Ethereum smart contract development;
  • InterPlanetary File system (IPFS): A peer-to-peer hypermedia protocol for decentralized file storage and sharing;
  • Next.js: A popular React framework for building server-rendered web applications;
  • Chakra UI: A set of accessible and customizable UI components for React applications.

🏗️ SETTING UP THE DEVELOPMENT ENVIRONMENT

STEP 1: INITIALIZE A NEXT.JS APP

bun create next-app

STEP 2: INSTALL HARDHAT

bun a --dev hardhat

STEP 3: INSTALL ETHEREUM LIBRARY

bun a --dev @nomicfoundation/hardhat-ethers ethers

STEP 4: CREATE A JAVASCRIPT PROJECT

bunx hardhat

STEP 5: INSTALL REQUIRED PACKAGES

bun a dotenv ipfs-api
bun a @chakra-ui/react @emotion/react @emotion/styled framer-motion @chakra-ui/icons
bun a react-icons

STEP 6: INITIATE THE HARDHAT NODE

bunx hardhat node

STEP 7: INITIATE THE IPFS DAEMON

ipfs daemon

STEP 8: COMPILE THE SMART CONTRACT

bunx hardhat compile

STEP 9: DEPLOY THE SMART CONTRACT

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

Post-deployment Operations (if the contract has been deployed previously)

  • remove the `artifacts` directory
rip artifacts
  • remove the `cache` directory
rip cache

⚙️ STARTING THE DEV SERVER

  • with Bun
bun --bun run dev
  • with Node.js
bun run dev

Visit http://localhost:3000 in your browser to access the application.

✅ CHECKLIST

Before you begin, ensure you’ve completed the following:

  • Installed Bun using the command
curl -fsSL https://bun.sh/install | bash
  • Installed IPFS
    • Install IPFS using Homebrew (one-time setup)
brew install ipfs

🤖 CODE STATISTICS

Tokei: A lightweight code counter with efficient directory code counting

LanguageFilesLinesCodesCommentsBlanks
HTML2730641287
JavaScript201695149213190
JSON5131571315601
Org2260225035
Solidity11801262133
Plain Text211108130
Total321613315640117376

🚨 ENVIRONMENT VARIABLES

This project relies on environment variables for configuring Ethereum and IPFS connections. Before running the project locally, make sure to set up a `.env` file in the root directory with the following content:

# -- ETHEREUM RPC URL -- #
LOCALHOST_URL=http://localhost:8545
HARDHAT_NETWORK_URL=http://localhost:8545

# -- IPFS RPC API SERVER -- #
IPFS_NODE_URL=http://localhost:5001
IPFS_HOST=localhost
IPFS_PORT='5001'

# -- IPFS GATEWAY URL -- #
IPFS_GATEWAY_URL=http://127.0.0.1:8080/ipfs

# -- IPFS CID HASHES -- #
CANDIDATE_0="replace_value"
CANDIDATE_1="replace_value"
CANDIDATE_2="replace_value"

# -- IPFS CID HASHES FILES -- #
IPFS_CONTRACT_METADATA="replace_value"
IPFS_ELECTION_GUIDELINES_CID="replace_value"
IPFS_EVENT_LOGS="replace_value"

# -- SMART CONTRACT ADDRESS -- #
VOTING_CONTRACT_ADDRESS="replace_value"

# -- AUTHORIZATION CHECK -- #
SMART_CONTRACT_OWNER_ADDRESS="replace_value"
SMART_CONTRACT_OWNER_PRIVATE_KEY="replace_value"

Replace the placeholder values with your actual Ethereum and IPFS configurations and CID hashes.

About

Blockchain-based voting dApp, a final year university project

Topics

Resources

Stars

Watchers

Forks