ManuGS2 / Blockchain

Implementation of a Blockchain within a distributed peer-to-peer network

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blockchain

This is blockchain-based application within a distributed peer-to-peer network.

Purpose

Main purpose of this dapp is to allow users whithin the network to communicate each others by posting messages. These messages are processed as transactions and mined in order to add them to the blockchain.

Pow algorithm

The proof of work for this blockchain is based on the hash of each Block that might contain one or more transactions. Each transaction is defined by the next info:

  • Author
  • Content
  • Timestamp

Each block is defined by the next:

  • Index
  • Transactions
  • Timestamp
  • Previous block (defined by its hash)

Algorithm consists in look for such a Nonce value that when calculating hash function for that block, result begin with "00".

Consensus algorithm

The consensus for this blockchain is as simple as just select the larger chain as the valid chain

Running

It's possible to run this Dapp (Descentralized Application) by two ways

This tutorial is assuming you have python installed and running on a Linux-based OS

Locally

If you go by this way, I suggest you to use virtual environment

  1. Clone this repo

git clone https://github.com/ManuGS2/Blockchain.git

  1. Go to the folder

cd Blockchain

  1. Install the dependencies
pip install -r server/requirements.txt
pip install -r front/requirements.txt
  1. Run the node server for connecting to blockchain network with the next commands
export FLASK_APP=server/blockchain_api.py
flask run --port 8000
  1. Run the web application with the next commands
export FLASK_APP=front/views.py
flask run --port 5000
  1. If you want to run more nodes, just follow the samen in step 4 but changing the port
export FLASK_APP=server/blockchain_api.py
flask run --port 8001

Your web application will be running on http://127.0.0.1:5000/

NOTE: for each instance of the web app or node server it's necessary to open new console window

Docker compose

If you go by this way, you need to have docker installed in your machine as well as docker-compose in onder to run this Dapp in containers.

If you don't have docker neither docker-compose installed follow the instructions from official page.

Once you have docker compose installed follow the next steps

  1. Clone this repo

git clone https://github.com/ManuGS2/Blockchain.git

  1. Go to the folder

cd Blockchain

  1. Build, crate and run the containers

docker-compose up --build

This last command will run the services defined in docker-compose.yml file. You can modify it in order to create more nodes or instances

By default this will create 1 web app instances, 2 nodes and 1 redis instance.

Your web application will be running on http://127.0.0.1:5000/

About

Implementation of a Blockchain within a distributed peer-to-peer network


Languages

Language:Python 75.2%Language:HTML 22.3%Language:Dockerfile 2.5%