The block and the blockchain¶
The block and the chain¶
Alice and Bob have wallets
A transaction is generated by Alice’s wallet when Alice sends Bob Smileycoins
Alice’s wallets broadcast the new transaction to the network
The transaction then enters the mempool
Any wallet on the network can examine the transaction
A miner aggregates these transactions into a block
A miner may simply be a wallet set to mine
The block is linked to the previous blocks in a chain
The miner broadcasts the block to the network
A block needs to satisfy certain difficulty criteria
(more later)
The hash and the nonce¶
See https://en.bitcoin.it/wiki/Block_hashing_algorithm to see the code below and a description of the composition of the header Handout ——-
The block hashing algorithm produces a sha256d hash of 256 bits (32 bytes) based on the following 640 bit input:
(from https://en.bitcoin.it/wiki/Block_hashing_algorithm) Examples ——–
Example python code:
>>> import hashlib
>>> header_hex = ("01000000" +
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +
"c7f5d74d" +
"f2b9441a" +
"42a14695")
>>> header_bin = header_hex.decode('hex')
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
>>> hash.encode('hex_codec')
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'
>>> hash[::-1].encode('hex_codec')
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'