Skip to content

It is a simple decentralized blockchain based voting system that has security aspects.

Notifications You must be signed in to change notification settings

qasem-talaee/voting-blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blockchain Based Voting System

It is a simple decentralized blockchain based voting system that has security aspects. Everyone has the right to vote only once with their id. The system ensures that the information of all nodes is up to date. Nodes can operate as a voting system or a mining system. The network is written in flask.

Master Node

The system uses a master node to identify the rest of the nodes to the network. A new node sends its information to the master node at startup.

The structure of a block

{
    "index": 2,
    "previous_hash": "d1a58a4282dc18cd726fbe25198b034588b959106458472b23473c9caddb589e",
    "proof": 35293,
    "timestamp": 1644346339.117375,
    "votes": [
        {
            "person_id": "5e1f08494c9f50dbaf5a7fd864fe0722996094d8d9044418225ea9ad2debde6c",
            "vote": "100"
        }
    ]
}

Installation

First, make sure you have the following packages installed.

sudo apt install python3-pip python3-venv

then get the source code and in source code directory:

python3 -m venv ./venv
source ./venv/bin/activate
pip3 install -r req.txt

and run it

python3 main.py

and in last you must enter your host address and port.for example

host : 127.0.0.1
port : 5050

Define your node to blockchain

Now, you must identify your device as a node to blockchain.for this you must send a get request to your device like this:

import requests
requests.get('http://<your-host>:<your-port>/init')

or you can do this with postman.

Work With Node

You can work with your node with send http requests to it.

Get all nodes list

address : /nodes
method : GET
parameters : None

Get all votes not added to the block

address : /current-votes
method : GET
parameters : None

Get blockchain

address : /chain
method : GET
parameters : None

Update all data of your node

address : /update-block
method : GET
parameters : None

Mine new block

address : /mine
method : GET
parameters : None

Count votes

address : /count-votes
method : GET
parameters : None

Add a new vote

Everyone id is added to the blockchain as a hash.Votes add with this format:

'1001'

That is, the first and last people have been voted. for add new vote:

address : /new-vote
method : POST
parameters : {
    'person_id': id,
    'vote': vote,
}

About

It is a simple decentralized blockchain based voting system that has security aspects.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages