cryptocurrency

in #bitcoin9 years ago

Introduction to Bitcoin

This document provides a fast-paced interactive introduction to basic Bitcoin concepts. The purpose is to give you enough knowledge of the Bitcoin protocol to write micropayments-capable apps and demos. Let’s dive in!

How to learn (enough) Bitcoin in one week
Bitcoin is a very highly interconnected subject and it can be tricky to explain one piece without assuming some knowledge of other pieces (or prerequisites). The approach we recommend you take is as follows:

Step 1: First, go and read the original paper by Satoshi Nakamoto (bitcoin.pdf)

Step 2: Next, set up your development environment using the instructions below.

Step 3: Now go through the Introduction to Bitcoin section and read through the questions to get a high level overview of Bitcoin

Step 4: Next, do the Interactive Introduction section and type in the commands. You won’t understand everything, but will learn by doing - kind of like immersion in a foreign language.

Step 5: Finally, skim the reference section if you see fit

You will then know enough Bitcoin to write Bitcoin apps!

How we’ve abstracted away Bitcoin guts so you can build Bitcoin apps
Note: don't worry if you don't fully understand everything you type in this first lab. The goal is to learn by doing, and you actually won't need to know much in the way of Bitcoin internals to do the projects in this class. As an analogy, you don't need to keep in mind the full seven layer model of the internet to simply perform an HTTP request. In the same way, we have abstracted away a big chunk of Bitcoin knowledge behind a little snippet of Python code that allows you to turn any web-accessible URL into a machine-payable endpoint. Here's a simple example of how that works (you don't need to run this now):

#!/usr/bin/env python3
from subprocess import call
from uuid import uuid4

from flask import Flask
from flask import request
from flask import send_from_directory

Import from the 21 Bitcoin Library

from two1.wallet import Wallet
from two1.bitserv.flask import Payment

Configure the app and wallet

app = Flask(name)
wallet = Wallet()
payment = Payment(app, wallet)

Charge a fixed fee of 3000 satoshis per request to the

/tts endpoint

@app.route('/tts')
@payment.required(3000)
def tts():
text = str(request.args.get('text'))
file = str(uuid4()) + '.wav'
call(['espeak', '-w', '/tmp/' + file, text])
return send_from_directory('/tmp', file, as_attachment=True)

if name == 'main':
app.run(host='::')
The key line there is the @payment.required(3000), which turns the call to this text to speech API into something which costs 3000 Satoshis per request. It does this by taking the existing tts function and wrapping it with a Python decorator. As you may already know, a decorator is a function that takes another function as an argument and modifies it by adding some shared setup or teardown code. In this case it modifies the tts function by requiring a Bitcoin micropayment for the function to execute.

Again, though the tricky parts of doing that are mostly hidden for you; for the purposes of this class, you should be able to just type payment.required before an endpoint and make it micropayments-capable. Our focus after next week is going to be at a higher level of the stack, more on the micropayments apps themselves than the mechanics of how the payment is completed.

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.084
BTC 61656.48
ETH 1593.99
USDT 1.00
SBD 0.47