Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

A fully functional blockchain application implemented in Python from scratch (with tutorial).

Notifications You must be signed in to change notification settings

catman85/python_blockchain_app

Open more actions menu
 
 

Repository files navigation

python_blockchain_app

A simple tutorial for developing a blockchain application from scratch in Python.

What is blockchain? How it is implemented? And how it works?

Please read the step-by-step implementation tutorial to get your answers :)

Instructions to run

Clone the project,

$ git clone https://github.com/catman85/python_blockchain_app.git

Install Prerequisites,

pip install flask, requests

Start a blockchain node server,

$ export FLASK_APP=node_server.py && flask run --port 8000

One instance of our blockchain node is now up and running at port 8000.

To run the application, with hot-reload

$ python run_app.py

The application should be up and running at http://localhost:5000

The server is running at http://localhost:8000

Use Case

1.Write some content, click post and then Request to mine

2.Have a look at the blockchain, by clicking at Show Chain

3.Resyncing with the chain for updated data

4.Write some new content and click post without clicking Request to mine. Then have a look at the pending transactions pool.

To play around by spinning off multiple custom nodes, use the add_nodes/ endpoint to register a new node.

Here's a sample scenario that you might wanna try,

# already running
$ flask run --port 8000
# spinning up new nodes
$ flask run --port 8001
$ flask run --port 8002

You can use the following cURL requests to register the nodes at port 8001 and 8002 with the already running 8000.

curl -X POST \
  http://127.0.0.1:8001/register_with \
  -H 'Content-Type: application/json' \
  -d '{"node_address": "http://127.0.0.1:8000"}'
curl -X POST \
  http://127.0.0.1:8002/register_with \
  -H 'Content-Type: application/json' \
  -d '{"node_address": "http://127.0.0.1:8000"}'

This will update the newer nodes with the longest chain, and the list of peers, so that they are able to actively participate in the mining process post registration.

To update the node with which the frontend application syncs, change CONNECTED_NODE_ADDRESS field in the views.py file.

Quick Startup

export FLASK_APP=node_server.py && flask run --port 8000

optional:

# spinning up new nodes
export FLASK_APP=node_server.py && flask run --port 8001
curl -X POST http://127.0.0.1:8001/register_with -H 'Content-Type: application/json' -d '{"node_address": "http://127.0.0.1:8000"}'
python run_app.py

:5000 is the client, :8000 is the server,

visit localhost:5000, localhost:8000/chain, localhost:8000/mine

About

A fully functional blockchain application implemented in Python from scratch (with tutorial).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 78.3%
  • HTML 18.2%
  • Shell 3.5%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.