satwikkansal / python_blockchain_app Goto Github PK
View Code? Open in Web Editor NEWA fully functional blockchain application implemented in Python from scratch (with tutorial).
A fully functional blockchain application implemented in Python from scratch (with tutorial).
Hi Satvik,
I'm facing issue similar to issue 25 and 32. I'm running the server on port 8000 and the application on port 5000, when I enter some text on the app and click mine, it navigates to the URL--http://127.0.0.1:8000/mine which says URL not found. Can you please suggest how do I fix it?
I've attached screenshots for your reference.
response = requests.get('{}chain'.format(node))
this may be right
response = requests.get('{}/chain'.format(node))
I would like to add another pc to the network but not sure on how should I do that.I believed I have to edit this line "CONNECTED_NODE_ADDRESS field in the views.py file" but how should i initialize another node?
there are several issues after following the instructions given.
all is done and work properly but the problem is that in this project we have 2 ports and run separately in two terminals .
terminal 1:
i) node_server.py 127.0.0.1:8000
terminal 2:
ii) run_app.py 127.0.0.1:5000.
i want to run this project in a single port and only one terminal in use.
what are the changes of the code to run this project in a single port instead of two different ports.
While mining I am getting the issue. May I know where I am going wrong.
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
The link to the discussion of your project is missing on IBM's site. Is there a backup?
NameError: name 'app' is not defined
You have mentioned in proof_of_work function that we have to generate hash code until it satisfies our difficulty criteria. But how can we generate different hash codes when hash code for a string remains same no matter how many times we run the algorithm ?
I am new to git! many thanks. ❤❤
[instances]
[running]
[later]
[conclusions]
If port=8000 goes down then the entire system crashes. All data lost 😢
[exceptions handled]
1.
requests.exceptions.ConnectionError
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /chain (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000232FF828048>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
I was wondering what is the transaction block size limit since blockchains usually have a 1MB limit on their blocks.
When a mining started, it can take too long depending on how the difficulty have been configured, so when that operation start the api is waiting the process end before return a response, it's same when trying to access the api with any other endpoint /chain,... etc, so i suggest to use threads as i do:
from threading import Thread
def mine():
.... mine() content....
...... some code here...
@app.route.....
def request_for_mine():
.... some code here....
# Launch the thread for the mine process, so that the API will be still available
Thread(target = mine).start()
return response
Hi Satwik,
Thanks for putting this all together!
Is it possible to mine from other nodes?
For example, in the web interface (localhost:5000), I post from node1, is it possible to mine the transaction from node2 using the api? When interacting with the API http://localhost:8001/mine, the ledger does not update. The only way that I could mine is through http://localhost:8000/mine.
However, the ledger is being distributed, so it is visible and in sync at both http://localhost:8000/chain AND http://localhost:8001/chain.
At the moment, this project doest seem to support mining from any other nodes accept for port 8000, however, I could be missing something.
Why is the consensus function not being called anywhere in the program ?
The requested URL was not found on the server.
Hi,
I am trying to retrieve the chain data and post it under the data content on the web page, but all chain data content are being sent node 8000, instead of 5000.
I have four terminals open at the same time.
In the first terminal I execute:
$ export FLASK_APP=node_server.py && flask run --port 8000
In the second one:
$ flask run --port 8001
In the third one:
$ 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"}'
Which outputs "Registration Successful". All good so far.
In the fourth one I type:
$ python run_app.py
Here is the problem. When I visit localhost:5000, a loop is crashing the second node (:8001)
Looking at the second terminal I get this.
From my understanding this is caused by the get_chain() method which
calls consensus().
But consensus calls get_chain() back!
Am I missing something?
Really cool project btw. (As long as you run one node 😁)
Shouldn't all miners get notified when a transaction is submitted? If not, it's as if "my miners" validate "my transactions" and so do everyone else's. Instead of having a separation between dealers and miners where the latter compete to validate the transaction of the former. Just wanted to know if this was intentional
During consensus, we are checking the validity of chain.
chain = response.json()['chain'] is used to get the chain.
But during the registration process, we use create_chain_from_dump() function.
Inside the function, we create new block without hash attribute and add that block to a dummy blockchain using add_block method, which itself performs all hash related checks.
so if we use create_chain_from_dump to get the chain during the consensus step, check_chain_validity is redundant.
The link to the windows flask instruction was not fully clear. I wanted to share the resolution for this.
in CMD:
set FLASK_APP=node_server.py
flask run --port 8000
If a new node with a bigger chain than anyone's joins, wouldn't it be able to deceive everyone and everyone would accept its chain because it's the longest?
When I use curl or any other way to make a POST request to http://192.168.8.120:8000/register_with {"node_address": "http://192.168.8.119:8000"}
, both front end and backend stop and I'm no longer able to visit the webpage or make any requests.
I have 3 VM's currently setup networked together with static IP addresses:
192.168.8.119 - Node 1
192.168.8.120 - Node 2
192.168.8.121 - Node 3
Sending the Post Request
What the server shows and continues to show until it times out. At this point everything on this node (192.168.8.120) stops working until the request times out.
...
Node 1 after the post request is sent
Response of the POST request after the request times out
No matter which Node I use or which Node I'm registering, it happens each time.
When consensus is called it calls chain calling consensus again forming infinite loop
First of all thanks satwikkansal for an awesome blockchain python tutorial!
When I tried to register a new node with an existing node by using these commands
$ flask run --port 8001
(in a new terminal tab)$ 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"}'
I got this returned back -
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
I checked the tab with port 8001, and I found port 8001 does receive this request, but also it shows a 404 error:
127.0.0.1 - - [31/Mar/2020 23:14:21] "POST /register_with HTTP/1.1" 404 -
Could anyone help me overcome this issue? Thanks!
I finish all code like you write.
And also follow your "How to run" instructions.
But when i click any buttons on the webpages, there is a Not Found error.
From my understanding, one mine confirms one transaction and records it on one block. So is this something that simulate any real wolrd processing, like bitcoin network? Or, it is just want to keep the things simple to understand?
I have followed these steps to run project but I am not able to execute it:
Step 1: I have cloned the complete project from github.
Step 2: I am using windows 10 so I have opened command prompt and set:
SET FLASK_APP=node_server.py
flask run
After executing step 2: I see following message on the screen:
Step 3:
When i am typing http://127.0.0.1:5000/ in browser it says:
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
When i checked the trace in command prompt, it says:
HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /chain (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x03C0A4A8>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
127.0.0.1 - - [25/Mar/2020 13:44:49] "�[35m�[1mGET / HTTP/1.1�[0m" 500 -
Kind help in this regard is highly appreciated.
can I know where is the data stored on my computer?
the data means that info I was inserting
Following the instructions in the latest version of ubuntu with the full python stack, we're encountering an internal server error. We put the run_app in debug=false and assigned a static IP to the node and receive a command line error of "Failed to establish a new connection: (Errno 111) connection refused. We have disabled all firewalls and port forwarding.
Please Satwik Kansal,
You had a nice text explaning line per line your project at this link:
"Please read the step-by-step implementation tutorial to get your answers :)" [https://www.ibm.com/developerworks/cloud/library/cl-develop-blockchain-app-in-python/index.html]
I was reading and studying using it but IBM remove.
Please, Is this text posted in another place?
Thank you and nice project!
Hello! I am very new to blockchain, and have been taking a class about it for the past 10 weeks. At the end of the term, the teacher suggested my group follow your tutorial on how to make an actual blockchain with python. After following your guide, I was curious, would there be any way to deploy this so the class can play with it while I am talking about it? If you have any tips on how I can do this that would be great.
Thank you for taking the time,
Trent Farley
"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"
CONNECTED_NODE_ADDRESS = "http://127.0.0.1:8000"
What change has to be made to views.py ?
I have this error: requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /chain (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000021A10EC5C10>: Failed to establish a new connection: [WinError 10061] No se puede establecer una conexión ya que el equipo de destino denegó expresamente dicha conexión'))
what would i do to solve it and run the code? cheers
where do you save reward transaction for mining a block ?
Thanks
In using litecore, I notice the ledger population pickups at the same place where left off if a node is shutdown. This indicates a flat storage of the ledger. Have you considered moving from runtime storage to more of a flat storage. I have been using UnQLite.
how can i add smart contract to this blockchain?
thanks
Hi there,
I love this project... I received a typeerror message on the :5000 instance. This was resolved by replacing
chain = json.loads(response.content)
with
chain = json.loads(response.content.decode('utf-8'))
in the '/app/view.py' file
Hi there,
actually my problem is similar to this case: [https://github.com//issues/32].
I adapted all recommendations on this solution, but still facing some challenges...
If I want to execute the Blockchain, Pot http://127.0.0.1:8000/ opens:
If I want do enter some data, and klick on request to mine, I get Not found:
This is how it looks on my terminal:
Honestly, I don´t find my mistake and I guess it might be a really tiny mistake - since am still very new in to programming...
Would be great, if someone could help me/give me a hint!
Thank you so much in advance for your help.
When a new register is done (one node to another), the "parent" node, or the node who receives the request never returns its own node_adress. For that reason, on children Node will be always necessary to register first a node, and then syncing.
I'll open a new branch, but not sure if I'm missing something.
Ty!
I trying to add another node by running the app again on port 5001 as I am running one on 5000. I am able to use the free ngrok version to run it that way. If i go to the node server and go to /add_nodes it gives a 405 error. What am I doing wrong?
When i was trying to run the application as explained in the readme there is an error on the following command
> flask run --port 8000
[.....]
ImportError: cannot import name 'soft_unicode' from 'markupsafe'
After searching online i found that there is a breaking change in the library that has been made recently that causes this issue.
Pinning the version in the requirements fixes the issue.
markupsafe==2.0.1
I am new to all of this, including Python, Flask, json, and venv. I have found my way through all issues, but am faced with one I can't resolve.
When I apply all the curl commands to execute the \register_with endpoint, I get an error showing that the the json object in the POST is not subscriptable - a 'NoneType' object is returned. What is up?
Screenshot shows my two nodes running node_server.py, the additional cmd shell with the curl statement, and the node 8001 error message on line 219 of node_server.py. I can't figure this out. Any assistance is appreciated.
I hope this image comes through and is useful, I am also new to GitHub.
While this is not a critical issue to my current project (I am expanding some features and functionality for a Python class final project) I would like to understand my failing and further understand this application and how it functions.
Thanks, Peter Thompson
Press butto POST generates:
Traceback (most recent call last):
File "c:\pf_c\python38\lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "c:\pf_c\python38\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "c:\pf_c\python38\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "c:\pf_c\python38\lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "c:\pf_c\python38\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "c:\pf_c\python38\lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "F:\Alexandria\Devel\GITRepoWork\python_blockchain_app\app\views.py", line 64, in submit_textarea
requests.post(new_tx_address,
File "c:\pf_c\python38\lib\site-packages\requests\api.py", line 119, in post
return request('post', url, data=data, json=json, **kwargs)
File "c:\pf_c\python38\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "c:\pf_c\python38\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "c:\pf_c\python38\lib\site-packages\requests\sessions.py", line 685, in send
r.content
File "c:\pf_c\python38\lib\site-packages\requests\models.py", line 829, in content
self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
File "c:\pf_c\python38\lib\site-packages\requests\models.py", line 754, in generate
raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)", ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
127.0.0.1 - - [29/Nov/2020 19:09:24] "←[35m←[1mPOST /submit HTTP/1.1←[0m" 500 -
Thanks for Your info [email protected]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.