Bitcoin is a cryptocurrency using the blockchain technology, which I discussed here. It’s completely digital and has no central bank controlling it.
Based on the previous article, we now understand what blockchain is & how it works. But it’s probably not clear how that technology relates to a cryptocurrency.
The components of a block
We know that the block chain looks something like the below. We have the data, in this case a group of transactions; the hash of the previous block; the nonce (which is something we haven’t seen before (and I will discuss below)) and the hash of the current block.
FIrst off, let’s think about the data. I said ‘a group of transactions’. That’s weird, right? Each block should be one transaction? No; the Bitcoin network has been designed to only allow one new block to be created every 10 minutes; so the transactions within those 10 minutes are grouped together into a single block.
We have the previous block hash, as we would expect based on our understanding of blockchain from the previous article; this helps to make the chain tamper resistant.
The block also contains this value called the nonce. This particular value can be manipulated by the Bitcoin miners. I’ll discuss a bit about mining & why they would want to manipulate that below.
Finally, we have the hash value of the current block, which is derived based on the data In the block; the previous block hash and the nonce.
How does the Bitcoin network work?
Let’s think about a scenario. I want to send Bob 100 Bitcoins. When I do so, the transaction has three components:
- A record of the sender address (i.e. me)
- A value (how many coins I want to send)
- A record of who I want to send it to (the receipient – Bob)
To understand how Bitcoin works, we need to understand a bit about public and private keys, which I have discussed here.
When I send a Bitcoin, it gets signed with my private key and sent to the Bitcoin address of the receipient (the Bitcoin address is the public key of the receipient). This now gets sent into the blockchain and is subsequently broadcast for miners to pick up.
Miners verify that my keys can access the sender address (my Bitcoin address) – validating that I have authority to send the coins.
Bitcoin mining is the process of ensuring that a block of transactions are valid & adding them to the ledger (blockchain). Bitcoin mining is not a mathematical problem that can be solved by any other means than trial and error. The Bitcoin network will set a cryptographic puzzle (known as proof of work). It will say, you must adjust the Nonce to ensure that the hash value is below a certain target.
Remember, that a hash is a hexadecimal number. So Bitcoin will say, that hexidecimal number must be below X. The miners then play around with adjusting the Nonce value until they meet that target. This is extremely computationally expensive. The lower the target, the harder the cryptographic puzzle is & the longer it takes. Bitcoin have set this to take on average 10 minutes to control the number of blocks created.
When a miner achieves the correct Nonce value, the block is committed to the Blockchain. The nodes in the blockchain then approve or reject it – by consensus (if the hash values don’t match, it will be rejected).
When a block is fully approved, the winning miner is awarded 12.5 Bitcoins (at time of writing). This is halved every 4 years to control the number of coins in circulation.
- The miners connect to the Bitcoin network & listen for transactions across the entire network.
- Check that the digital signatures prove you are the owner and authorised to send the coins
- Check the block chain to make sure you haven’t already spent this Bitcoin – copy of the blockchain is on all of the machines in the P2P network
- Solve the cryptographic puzzle by correctly guessing the nonce
- Alert other miners that you have solved it – they verify you are correct
- Add the block to the blockchain & await verification from the machines in the P2P network that this is legitimate (the hashes align etc..).
Above are the key steps. In an upcoming article, we will start making our own cryptocurrency & start mining.