Here’s a gentle intro to blockchain functionality using Anders Brownworth’s blockhain demo that you can find on Github here and running on Anders’ site here. The magic of the blockchain is basically 4 things: 1] shredding data blocks through a SHA256 encryption hash function 2] mixing in a random number called a nonce until a specific number of leading zeros exist in the hash — which takes some computer time — the more zeros the more time — and then you have proof you got there and share and store the news with 3] a network of other computers, and, finally 4] you always require that each new block point back to the verified block before it (and mix that previous block’s hash into the new block’s “hash-shredder”).
So let’s hash some stuff:
After you play with this live SHA256 hash window for a bit (notice things like one space changes the hash, one period does the same, a new word..etc ) let’s mine a block.
You’ll be running the block data through the hash function like before, but now there’s a new game — you need to bascially play a lottery that takes some computer time to get a unique number called a nonce that will create a hash with 4 leading 0s (in this example) — something like rolling a hundered dice till you get the first four to land on 1.
So, go to the block demo in the caption below, enter some text in block one, press mine and watch the nonce change and the hash update after mining.
The mined block will have 4 leading zeros (or whatever difficulty is set .. more zeros is more difficult ) in the new hash and will show the nonce that was required for the hash to turn out this way with the given block of data. If you changed the nonce or the block data the hash would change — just like you saw with the SHA256 hash demo above.
Now let’s build a blockchain! :)
Go to the blockchain demo in the caption link below and mine the first block.
Then put some data in the second block. Before you mine the second block, note the nonce that will change and the hash that doesn’t have the correct number of leading zeros yet. Also note a new field, called “Prev” which shows the mined hash from the first block — this is the chain in the word blockchain.
If the encryption and the random nonce weren’t enough to protect your data, you’ve now made a brilliant step of locking, linking or chaining, the new block to the previous block via the previous block’s verified, immutable and final hash.
Now mine the second block.
Note the new nonce and the 4 leading zeros now in the second block’s hash.
You’ve just mined and connected the first two blocks of your very own blockchain.