Skip to content

Z-Vote , Blockchain Voting System (Production Server)

BlockChain Based E-Voting System¤

  • This project aims at implementing a voting system based on Blockchain technology.
  • It is a secure, transparent and decentralized way of voting.
  • It converts ballots into transactions and securely mines blocks out of them.
  • The advantage of a blockchain based voting system include the ability to vote from any place and prevent any tampering of votes.

Report¤

Download

Technology stack used:¤

  1. Python 3.11.x
  2. Django Web Framework 4.2.1
  3. Bootstrap 4
  4. MySQL
  5. HTML5

Environment Variables.¤

  1. Go to API NINJA and signup to obtain the api key for passphrase generation.
  2. Create an Account on TWILIO and Buy a Phone Number to use the OTP Service.

Create and fill the 'env' file with the obtained APIs.¤


[+] Create a 'env' file in the root directory
    [-] DJANGO_SECRET_KEY=
    [-] DEBUG=
    [-] DJANGO_ALLOWED_HOSTS=
    [-] DJANGO_CSRF_TRUSTED_ORIGINS=
    [-] API_NINJA_API=
    [-] TWILIO_ACCOUNT_SID=
    [-] TWILIO_AUTH_TOKEN= 
    [-] TWILIO_PHONE_NUMBER= 
    [-] MYSQL_DATABASE=
    [-] MYSQL_USER=
    [-] MYSQL_PASSWORD=
    [-] MYSQL_ROOT_PASSWORD=

  • DJANGO_SECRET_KEY - Enter the Django Project Secret Key.(Generate random key here) .

  • DEBUG - Debug state of Django Project(Set to empty for False).

  • ALWAYS set to FALSE during PRODUCTION.


  • DJANGO_ALLOWED_HOSTS - Enter the domain name or ip used for accessing the application.

  • DJANGO_CSRF_TRUSTED_ORIGINS - Enter the link of your domain eg: https://domain_name.com or https://ip_address .

  • API_NINJA_API - Enter the API Token of Api Ninja for generating random passphrase.

  • TWILIO_ACCOUNT_SID - Enter the Twilio Account SID Obtained.

  • TWILIO_AUTH_TOKEN - Enter the Twilio Auth Token Obtained.

  • TWILIO_PHONE_NUMBER - Enter your Twilio Phone Number , Used for sending OTP.

  • MYSQL_DATABASE - Enter the MYSQL Database Name.

  • MYSQL_USER - Enter the MYSQL Username.

  • MYSQL_PASSWORD - Enter the MYSQL Password.

  • MYSQL_ROOT_PASSWORD - Enter the MYSQL Root Password.


An Example Of "env" File¤

DJANGO_SECRET_KEY=#sdfgg4g7h%-y8b+34_^s$yo^$a63&*$Fb3^d
DEBUG=False
DJANGO_ALLOWED_HOSTS=vote.com
DJANGO_CSRF_TRUSTED_ORIGINS=https://vote.com
API_NINJA_API=/ghjf53spoG657vghjygdr0qw==uRVWERV
TWILIO_ACCOUNT_SID=AA3w5fgdrfawd3459faedw4349a3b
TWILIO_AUTH_TOKEN=awd18f3ccac7329thfsf43fd4drgx1
TWILIO_PHONE_NUMBER=+134656544
MYSQL_DATABASE=zvote_db
MYSQL_USER=akkupy
MYSQL_PASSWORD=sreeku
MYSQL_ROOT_PASSWORD=sreeku

Create 'envdb' file in the same directory of env file and fill the below values.¤


  • USE THE SAME VALUES USED IN THE 'env' FILE.
[+] Create a 'envdb' file in the root directory
    [-] MYSQL_DATABASE=
    [-] MYSQL_USER=
    [-] MYSQL_PASSWORD=
    [-] MYSQL_ROOT_PASSWORD=


An Example Of "envdb" File¤

MYSQL_DATABASE=zvote_db
MYSQL_USER=akkupy
MYSQL_PASSWORD=sreeku
MYSQL_ROOT_PASSWORD=sreeku

Z-vote Production Server On Docker¤


Install Docker and Portainer if not already done.(refer here)¤


    1. Run the following script to clone the repository.

wget -qO- https://raw.githubusercontent.com/akkupy/Z-Vote/production/script/zvote.sh | bash


  1. Now we need to move into that directory using the following:

cd /home/$USER/Z-Vote


  1. Create an 'env' file .

sudo nano env


  1. Fill the environment variables for env file (see above).



  1. Create an 'envdb' file .

sudo nano envdb


  1. Fill the environment variables for envdb file (see above).



  1. Pull the docker image of Z-Vote and Nginx and Mysql.

docker pull akkupy/z-vote:latest
docker pull nginx:latest
docker pull mysql:latest


  • Change the ports of Nginx if you are already running a service on port 80 and 443 in the docker-compose.yml file



  1. Generate a SSL Certificate and copy the .key and .crt files into the directory given below.


 cd /home/$USER/Z-Vote/nginx


  • Rename the .key as vote.key and .crt as vote.crt
  • A self generated SSL certificate(which can be generated here)
  • Use Self Generated SSL Certificate For Local and Private VPN Networks.


  1. CD into the Z-Vote directory.

cd /home/$USER/Z-Vote


  1. Run the following command to start the containers.

docker compose up -d

  • WAIT FOR THE DATABASE TO BOOT UP(>1min)

  • Exec into the container using the command below

docker exec -it zvote sh


* You will see a new terminal like shown below.

/app #


  1. Run the following commands on the container terminal.

  2. Enter the username and password for the superuser when prompted.

python manage.py makemigrations poll
python manage.py migrate
python manage.py collectstatic --noinput
python manage.py createsuperuser


  1. Press Ctrl+D to exit the container Terminal.



Head Over to your domain name to see the web application!¤

  • Head over to https://domain_name/admin to add the voterlists in 'Voter lists' table and the candidates in the 'Candidates' table.

  • Set the Voting Time in 'Vote auths' table(Create only one object and add the start and end time of voting).

  • Now the project is ready for Voting!






Building Docker Container from Dockerfile (For Devs)¤

  • Clone the repository and Build the container:
    # Install Git First // (Else You Can Download And Upload to Your Local Server)
    $ git clone -b production https://github.com/akkupy/Z-Vote.git
    # Open Git Cloned File
    $ cd Z-Vote
    # Run Docker Build
    $ docker build -t <name>:<tag> .
    
  • Create env file(refer here)

  • Run and Configure the container(refer here)




Contact Me¤

telegram

License¤

GNU GPLv3 Image

This is a Free Software: You can use, study share and improve it at your will. Specifically you can redistribute and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

--This is only a demonstration of the blockchain based voting system and it is entirely a prototype of the technology--