Code Monkey home page Code Monkey logo

python_blockchain_app's Introduction

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/satwikkansal/python_blockchain_app.git

Install the dependencies,

$ cd python_blockchain_app
$ pip install -r requirements.txt

Start a blockchain node server,

# Windows users can follow this: https://flask.palletsprojects.com/en/1.1.x/cli/#application-discovery
$ export FLASK_APP=node_server.py
$ flask run --port 8000

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

Run the application on a different terminal session,

$ python run_app.py

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

Here are a few screenshots

  1. Posting some content

image.png

  1. Requesting the node to mine

image.png

  1. Resyncing with the chain for updated data

image.png

To play around by spinning off multiple custom nodes, use the register_with/ 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 make the node at port 8000 aware of the nodes at port 8001 and 8002, and make the newer nodes sync the chain with the node 8000, so that they are able to actively participate in the mining process post registration.

To update the node with which the frontend application syncs (default is localhost port 8000), change CONNECTED_NODE_ADDRESS field in the views.py file.

Once you do all this, you can run the application, create transactions (post messages via the web inteface), and once you mine the transactions, all the nodes in the network will update the chain. The chain of the nodes can also be inspected by inovking /chain endpoint using cURL.

$ curl -X GET http://localhost:8001/chain
$ curl -X GET http://localhost:8002/chain

python_blockchain_app's People

Contributors

satwikkansal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.