Instantly share code, notes, and snippets.

@dvf /blockchain.py
Last active Jan 16, 2018

Embed
What would you like to do?
Step 6: Setting up Flask
import hashlib
import json
from textwrap import dedent
from time import time
from uuid import uuid4
from flask import Flask
class Blockchain(object):
...
# Instantiate our Node
app = Flask(__name__)
# Generate a globally unique address for this node
node_identifier = str(uuid4()).replace('-', '')
# Instantiate the Blockchain
blockchain = Blockchain()
@app.route('/mine', methods=['GET'])
def mine():
return "We'll mine a new Block"
@app.route('/transactions/new', methods=['POST'])
def new_transaction():
return "We'll add a new transaction"
@app.route('/chain', methods=['GET'])
def full_chain():
response = {
'chain': blockchain.chain,
'length': len(blockchain.chain),
}
return jsonify(response), 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
@emman27

This comment has been minimized.

Copy link

emman27 commented Oct 19, 2017

import jsonify is missing by the way (see line 38)

@Niedzwiedzw

This comment has been minimized.

Copy link

Niedzwiedzw commented Jan 13, 2018

What's jsonify?

@volf52

This comment has been minimized.

Copy link

volf52 commented Jan 16, 2018

Could you change line 7 to
from flask import Flask, jsonify?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment