truElect Dapp

Table of contents

Overview

TruElect as an app which can be used to setup an election. The major voters here include the voters and the members of the election committee, who are involved in stetting up the election.

Core Features Implemented

  • Deployment on polygon for speed, gas fees & optimization.
  • Batch upload voter addresses and mint certain amount of tokens to voters during upload.
  • Restrict the voting power of voters to only those who have a token.
  • Restrict the power to set up and collate votes to only the election committee head and electoral committee.
  • Set up multiple elections at the same time.
  • Restrict the ability for anyone who isn't a authorized voter to vote.
  • Allow eligible voters to vote for candidates in different election categories simultaneously.
  • Limit authorized voters from voting in specific elections, for example voters can't vote in an election for assigning electoral committee.
  • Register candidates to contest for specific positions.
  • Restrict authorized voters from voting multiple times for different candidates in the same election category.
  • Prevent voters from voting for a candidate that doesn't exist for that category.
  • Allow authorized voters to view history of past elections.
  • Allow for the election committee to view the election queue.
  • Restrict the beginning and end of a voting session to only the election committee head.
  • Collate votes for different election categories.
  • Grant ability to broadcast the election results to the election committee head and election committee.
  • Restrict the ability of the voters to view the election results until it is broadcasted.
  • Change the current election committee head based on a consensus of above 80% vote from the election committee.
  • Pause and unpause the contract in the event of a vulnerability or a security breach. This pauses the contract functionality so the vulnerability can't be exploited until the problem has been resolved.
  • Unit testing to ensure that all the codes meet the quality standards and the functions return the expected output. Test coverage shows us the extent of how much of our codes are covered by tests. We ideally aim for 100% coverage.
  • This documentation provides information about the codebase and their implementation for both technical and non technical people.

Technologies

Stack Usage
Solidity Smart contract
React JS Frontend

Repo Setup

To setup the repo, first fork the Team-LADS truElect repo, then clone the forked repository to create a copy on your local machine.

$ git clone https://github.com/<your-forked-repo>/truElect.git

Change directory to the cloned repo and set the Team-LADS truElect repository as the "upstream" and your forked repository as the "origin" using gitbash.

$ git remote add upstream https://github.com/Team-LADS/truElect.git

Requirements

  • Hardhat
  • Alchemy key
  • Metamask key
  • Polygonscan.com API Url
  • Node JS

Setup the Project

*Note:

This project was setup on a windows 10 system using the gitbash terminal. Some of the commands used may not work with the VScode terminal, command prompt or powershell.

The steps involved are outlined below:-

Install Hardhat

The first step involves cloning and installing hardhat.

# cd truElect

$ npm i -D hardhat

$ npm install

$ npm i --save-dev "@nomiclabs/hardhat-waffle" "ethereum-waffle" "chai" "@nomiclabs/hardhat-ethers" "ethers" "web3" "@nomiclabs/hardhat-web3" "@nomiclabs/hardhat-etherscan" "@openzeppelin/contracts" 

$ npm i --save-dev "dotenv" "@tenderly/hardhat-tenderly" "hardhat-gas-reporter" "hardhat-deploy" "ganache" "ganache-cli" "solidity-coverage"

Env Setup

Next create a .env file by using the sample.env. Retrieve your information from the relevant sites and input the information where needed in the .env file.

To retrieve your metamask private key.

  • Open your account details by clicking on the three dots on the metamask extension on your chrome browser
  • Click on export private key
  • Verify your password
  • Copy your private key and place it in the .env file

metamask

To retrieve your alchemy key.

  • Login to your account on alchemy
  • Once you're redirected to your dashboard, click on create app.
  • Fill in the relevant details especially the chain and network
  • Once the app has been created, click on view key.
  • Copy the HTTP and place it in the .env file.

alchemy

To retrieve your polygonscan key.

  • Login to polygonscan and hover over the dropdown arrow for your profile on the navbar.
  • Click on API keys and add to create a new project (optional step).
  • Once the project has been created, click on the copy button to copy the API key.
  • Paste it in the .env file

polygon key

Setup Hardhat.config

Below is the setup for the hardhat.config.json

hardhat

Create the SmartContract

  • First write the Smartcontract codes within the contracts folder.
  • The next step involves the compilation, deployment and verification of the contract on the testnet.

Compile

  • To compile the smartcontract before deployment:
$ npx hardhat compile

Deploy

  • To deploy the smartcontract:
$ npx hardhat run scripts/deploy.js --network mumbai

Verify

  • To verify the smartcontract:
  • Note for verification, the first address is the TruElectToken address, while the second is the TruElect address.

Setup the Frontend

  • First run the frontend on your local server to ensure it's fully functional before building for production.

Install Dependencies

  • Setup and install dependencies
# cd frontend

$ npm install

$ npm run dev

Testing the Smartcontract

  • Coverage is used to view the percentage of the code required by tests. Unittests were implemented to ensure that the code functions without errors

Coverage Test

  • To test the smartcontract, first open a terminal and run the following command:
  • Add require('solidity-coverage') to hardhat.config.json
  • Run coverage
$ npx hardhat coverage --network localhost

# if you get errors and you want to trace the error in the terminal
$ npx hardhat coverage --network localhost --show-stack-traces

coverage tests

Contributors

This Project was created by the members of Team-LADS during the Polygon Internship.

- KordJs (Ajibadeabd@gmail.com)
- Sancrystal (anyanwu.amanzearthur@gmail.com)
- PaulineB (paulinebanye@gmail.com)

Contributing to the project

If you find something worth contributing, please fork the repo, make a pull request and add valid and well-reasoned explanations about your changes or comments.

Before adding a pull request, please note:

  • This is an open source project.
  • Your contributions should be inviting and clear.
  • Any additions should be relevant.
  • New features should be easy to contribute to.

All suggestions are welcome!

README Created by pauline-banye for Team-LADS