- 🚀 TL;DR
- 🎬 DEMO
- 🎯 OVERVIEW
- 🛠 TECHNOLOGIES AND TOOLS
- 🏗️ SETTING UP THE DEVELOPMENT ENVIRONMENT
- ⚙️ STARTING THE DEV SERVER
- ✅ CHECKLIST
- 🤖 CODE STATISTICS
- 🚨 ENVIRONMENT VARIABLES
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.
This guide will walk you through the following key steps:
- Setting up the development environment.
- Deploying the smart contract on the local Hardhat Ethereum development environment.
- Implementing the Mi-Voting dApp.
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.
bun create next-app
bun a --dev hardhat
bun a --dev @nomicfoundation/hardhat-ethers ethers
bunx hardhat
bun a dotenv ipfs-api
bun a @chakra-ui/react @emotion/react @emotion/styled framer-motion @chakra-ui/icons
bun a react-icons
bunx hardhat node
ipfs daemon
bunx hardhat compile
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
- with Bun
bun --bun run dev
- with Node.js
bun run dev
Visit http://localhost:3000 in your browser to access the application.
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
Tokei: A lightweight code counter with efficient directory code counting
Language | Files | Lines | Codes | Comments | Blanks |
---|---|---|---|---|---|
HTML | 2 | 730 | 641 | 2 | 87 |
JavaScript | 20 | 1695 | 1492 | 13 | 190 |
JSON | 5 | 13157 | 13156 | 0 | 1 |
Org | 2 | 260 | 225 | 0 | 35 |
Solidity | 1 | 180 | 126 | 21 | 33 |
Plain Text | 2 | 111 | 0 | 81 | 30 |
Total | 32 | 16133 | 15640 | 117 | 376 |
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.