- Notifications
You must be signed in to change notification settings - Fork466
satwikkansal/python_blockchain_app
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A simple tutorial for developing a blockchain application from scratch in Python.
Please read thestep-by-step implementation tutorial to get your answers :)
Clone the project,
$ git clone https://github.com/satwikkansal/python_blockchain_app.git
Install the dependencies,
$cd python_blockchain_app$ pip install -r requirements.txtStart a blockchain node server,
$export FLASK_APP=node_server.py$ flask run --port 8000set LANG=C.UTF-8set FLASK_APP=node_server.pyflask run --port 8000One 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
set LANG=C.UTF-8set FLASK_APP=run_app.pyflask run --port 8000The application should be up and running athttp://localhost:5000.
Here are a few screenshots
- Posting some content
- Requesting the node to mine
- Resyncing with the chain for updated data
To play around by spinning off multiple custom nodes, use theregister_with/ endpoint to register a new node.
Here's a sample scenario that you might wanna try,
# Make sure you set the FLASK_APP environment variable to node_server.py before running these nodes# 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 port8001 and8002 with the already running8000.
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), changeCONNECTED_NODE_ADDRESS field in theviews.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
About
A fully functional blockchain application implemented in Python from scratch (with tutorial).
Topics
Resources
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.


