What is a block?
A block is a bunch of transactions that have been added to the blockchain.
How are blocks formed?
Blocks are formed by miners.
When you make a bitcoin transaction, it isn’t added to the blockchain straight away. Instead, it is held in a transaction pool (or memory pool).
If you are a miner, your job is to gather transactions from the transaction pool in to a “candidate block”, and to try and add this candidate block to the blockchain.
You also can give each candidate block a block header, which is basically a bunch of metadata about the block.
Miners use this metadata when trying to add a block to the blockchain.
metadata – n. data that describes other data, serving as an informative label.
How are blocks added to the blockchain?
To add a candidate block to the blockchain, you hash the data in the block header and hope that the result is below a certain target value.
The target is calculated from the difficulty, which is a value set by the bitcoin network to regulate how difficult it is to add a block of transactions to the blockchain.
Think of the target as the limbo pole for candidate blocks – the greater the difficulty, the lower the target, and the more difficult it is to find a block hash that is below this value.
Don’t worry, I know this difficulty and target business is a little confusing at first, but it will make more sense over time.
- A value set by the bitcoin network that is designed to regulate how quickly blocks are solved. It adjusts every 2016 blocks to try and create an average of 10 minutes between blocks.
I lied. You don’t actually hash the block header on its own. You actually hash it with an extra number.
This number is called a nonce, and it’s basically a dummy field that miners use to help them get a block hash below the target value.
nonce – an arbitrary number used only once in a cryptographic communication.
If the first nonce doesn’t work (starting at 0), keep incrementing it and hashing the block header. Eventually you’ll find a nonce that returns a block hash that is less than the target value.
I know these hash values contain letters, but you can still think of them as numbers like any other. They’re simply hexadecimal values, and computers love working with them.
Once you’ve found nonce that works, the block is “solved” and all of the transactions in this block are added to the blockchain.
All miners will now head back to the transaction pool and start work on the next candidate block. They will use your successful block hash in their next block header, and the race to add a new block of transactions to the blockchain starts again.