intro to block chain bitcoin. blocks ●ethereum - block chain ●dogecoin - block chain ●ripple -...
TRANSCRIPT
Intro to Block ChainBitcoin
Blocks
Blocks
● Ethereum - block chain● Dogecoin - block chain● Ripple - not a block chain● Stellar - not a block chain
● Bitcoin - definitely a block chain
Blocks
Q. What makes a block chain?A. Blocks + Proof of Work/Mining
Consensus
● Paxos - Google’s chubby● Raft - CoreOS etcd● Proof of work - Bitcoin
Proof of Work
A function which is hard to compute but easy to verify.
Proof of Work Examplevar target = '00';var data = 'block chain u';var result = '';var nonce = 0;
for(;;) { var f = crypto.createHash('sha256'); var h = f.update(data + ++nonce); result = h.digest('hex'); if (result.slice(0, target.length) == target) { break; }}
var check = crypto.createHash('sha256').update(data+nonce).digest('hex');if (check.slice(0, target.length) == target) { console.log('Verified nonce='+nonce);}
Proof of Work
ƒ(data,nonce) < 2^256 / difficulty
Block Creation
Coinbase Transactions
If you proved the work you send yourself 25 BTC as a reward.
You also get to collect fees.
Miners Are Important
They decide which transactions make it into a block and ingest new BTC.
Addresses
Private Key -> Public Key -> Address
Addresses
● Don’t contain 0 O I l (base58)● Start with a 1● 33 or 34 characters long● Shorter and more recognizable than public
key● Might help if there is an ECDSA Attack● Should be used only once
Private Key Storage
● If you lose your private key, the funds are forever gone
var bitcoin = require('bitcoinjs-lib');
var prv = bitcoin.ECKey.makeRandom()var pub = prv.pub;
console.log('private=' + prv.toWIF());console.log('public=' + pub.toHex());console.log('address=' + pub.getAddress());
//Output:private=L44GNX8FAMENVyae31mK34p5mpSVGBfEW5xZvmVrD8gULNfTAv3Ypublic=02570b2cec80ac066f7ebbf3ac10f13710707525a5b2effca71c47b87ecd8b78ccaddress=19aHhFTKfH7Zuccjrkc4H1gkJNQJ8mC15Q
Creating an Address
Transactions
Satoshi
● 1 BTC = 100000000 Satoshis● Minimum transactions size = 5430 Satoshis
Transaction Outputs
● Must consume entire value● Value not consumed will be left as fee 😱● If an output isn’t named in an input, it is
considered unspent● You can be named in an output without
consent
Standard Transaction Types
● P2PKH - Pay to Public Key Hash● P2SH - Pay to Script Hash● Multisig - Most people use P2SH● Null Data - Store 40 arbitrary bytes● Public Key - Most people use P2PKH
P2PKH Script Validation
Creating A Transactionvar key = bitcoin.ECKey.fromWIF("L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy")var tx = new bitcoin.TransactionBuilder()tx.addInput("aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31", 0);tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK", 15000);tx.sign(0, key);console.log(tx.build().toHex());
Smart Contracts
● Arbitration using P2SH● Wills & Inheritance using nLockTime● Bets using Oracles and hashed scripts
Payment Requests
● Generate addresses on demand● Meta-data for building the transaction
Software
● Libraries● Full nodes● SPV nodes● Wire protocol
Bitcoin Core (bitcoind)
● C++● The original Bitcoin software● Full node● Stores data on disk● JSON RPC● Wallet code will most likely be pulled
btcd
● Go● btcwire● btcutil● btcscript● btcnet
bitcoinj
● Java● Wallet features
bitcoinlib-js
● Node.js / Browser● Really easy to use 👌
APIs
● Unspents by address● Transactions by address● Transaction broadcasting● Network propagation levels● Push data
Resources
● reddit.com/r/bitcoin● bitcoin.org/en/developer-guide● bitcoin.org/en/development● BIPS: github.com/bitcoin/bips● Testnet● http://blog.chain.com/post/92058053671/ios-
8-touch-id-wallet-demo