Skip to content

Instantly share code, notes, and snippets.

@dvf
Last active June 24, 2019 11:36
Show Gist options
  • Save dvf/a61aceea175b9a2d7a0f58850ca3d610 to your computer and use it in GitHub Desktop.
Save dvf/a61aceea175b9a2d7a0f58850ca3d610 to your computer and use it in GitHub Desktop.
Step 7: Transaction Endpoint
import hashlib
import json
from textwrap import dedent
from time import time
from uuid import uuid4
from flask import Flask, jsonify, request
...
@app.route('/transactions/new', methods=['POST'])
def new_transaction():
values = request.get_json()
# Check that the required fields are in the POST'ed data
required = ['sender', 'recipient', 'amount']
if not all(k in values for k in required):
return 'Missing values', 400
# Create a new Transaction
index = blockchain.new_transaction(values['sender'], values['recipient'], values['amount'])
response = {'message': f'Transaction will be added to Block {index}'}
return jsonify(response), 201
@NDS1608
Copy link

NDS1608 commented Mar 3, 2018

I keep getting "
response = {'message': f'Transaction will be added to Block {index}'}

SyntaxError: invalid syntax
(With the carrot under the ' at the end of the line)
Can't figure it out, any ideas?

@stackotter
Copy link

Are you using python 3?

@dsp90
Copy link

dsp90 commented Jun 24, 2019

it's because this is introduced in python version 3.6

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