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.
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.
{
"index": 2,
"previous_hash": "d1a58a4282dc18cd726fbe25198b034588b959106458472b23473c9caddb589e",
"proof": 35293,
"timestamp": 1644346339.117375,
"votes": [
{
"person_id": "5e1f08494c9f50dbaf5a7fd864fe0722996094d8d9044418225ea9ad2debde6c",
"vote": "100"
}
]
}
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
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.
You can work with your node with send http requests to it.
address : /nodes
method : GET
parameters : None
address : /current-votes
method : GET
parameters : None
address : /chain
method : GET
parameters : None
address : /update-block
method : GET
parameters : None
address : /mine
method : GET
parameters : None
address : /count-votes
method : GET
parameters : None
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,
}