The Decentralized Voting System harnesses the power of Ethereum blockchain technology to create a transparent, tamper-proof, and fraud-resistant method of conducting elections. By allowing remote voting while ensuring voter anonymity, this system sets a new standard for trustworthy voting processes. Here’s how you can set it up on your own!
Key Features
- Utilizes JWT for secure voter authentication and authorization.
- Leverages Ethereum blockchain for transparent and tamper-proof voting records.
- Removes the necessity for intermediaries, ensuring a trustless voting process.
- Offers an admin panel to manage candidates and monitor results.
- Provides an intuitive UI for voters to cast their votes and view candidate information.
Requirements
- Node.js (version – 18.14.0)
- Metamask
- Python (version – 3.9)
- FastAPI
- MySQL Database (port – 3306)
Installation Steps
- Open a terminal.
- Clone the repository using the command:
git clone https://github.com/Krish-Depani/Decentralized-Voting-System-Using-Ethereum-Blockchain.git
- Download and install Ganache.
- Create a workspace named bdevelopment.
- Download Metamask extension for your browser.
- Follow the setup instructions for Ganache and Metamask to establish your local Ethereum network.
- Open MySQL and create a database named voter_db.
- Create a table named voters in the database using the provided SQL code:
CREATE TABLE voters ( voter_id VARCHAR(36) PRIMARY KEY NOT NULL, role ENUM(admin, user) NOT NULL, password VARCHAR(255) NOT NULL );
- Install Truffle globally with:
npm install -g truffle
- Navigate to the root directory of the repo and install node modules:
npm install
- Install Python dependencies:
pip install fastapi mysql-connector-python pydantic python-dotenv uvicorn uvicorn[standard] PyJWT
Usage Instructions
Now that you have everything set up, here’s how you can run your decentralized voting app.
- Open a terminal in the project directory.
- Open Ganache and load your bdevelopment workspace.
- Run the following command to compile the smart contracts:
truffle console
- Exit the Truffle console and bundle your app.js using:
browserify ./src/js/app.js -o ./src/dist/app.bundle.js
- Start the Node server:
node index.js
- Navigate to the Database_API folder in another terminal and run:
uvicorn main:app --reload --host 127.0.0.1
- In a new terminal, migrate the Truffle contract to the local blockchain:
truffle migrate
Your Voting app should now be live at http://localhost:8080.
Understanding the Code Structure with an Analogy
Imagine your decentralized voting system as a well-oiled factory. Each section of the factory has a designated role:
- Root Directory – This is the entrance to our factory, where everything begins.
- build – Think of this as the quality control department where compiled contracts are stored, ensuring that only the best products are released.
- contracts – This is the manufacturing section where our smart contracts—the essential parts of the voting process—are created and refined.
- public – It represents the showroom where voters can check the assets of the system, just like how products are displayed for consumers.
- Database_API – This is the logistics center that ensures smooth communication between the front-end and back-end, supporting our voting processes.
With each department working in harmony, the factory can operate efficiently, ensuring that voters can cast their votes securely and anonymously.
Troubleshooting
Here are some common issues you may encounter during setup and how to resolve them:
- Issue: Unable to connect to the local blockchain.
- Solution: Make sure Ganache is running and the network configuration matches what you set up in Metamask.
- Issue: Database connection errors.
- Solution: Double-check that you created the database and the necessary tables as per the instructions and ensure that credentials in your .Database_API.env file are correct.
- Issue: Voting app not loading.
- Solution: Verify that all your servers (Node.js and Uvicorn) are running, and check your terminal for error messages.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
By following the installation and usage guidelines, you should have a fully functional decentralized voting system utilizing Ethereum Blockchain technology. As technology progresses, integrating such solutions is vital for ensuring the integrity and security of our democratic processes.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.