- Assume this is the hash of the lastest block (shortened to 30 characters):
00000000000001adf44c7d69767585
- Following are the hashes of a few valid transactions waiting for inclusion (shortened).
5572eca4dd4
db7d0c0b845
- And this the hash of one special transaction that you just crafted, which gives 10BTC (the current reward) to yourself:
916d849af76
- Roughly your new block might look something like this (the real one uses binary format). It contains the hash of the previous block and the hashes of those 3 transactions:
00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--
- Let's do mining using linux terminal window.
- The goal is to complete this block with a nonce (a piece of garbage number) such that the hash of the new block starts with 13 zeros. The more the number of leading zeros, more difficult it is to mine. Current difficulty level is with 16 leading zeros.
- Let's try with nonce=1, and compute the hash of the block (I'm using the md5 hash algorithm, but Bitcoin uses double sha256):
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--1" | md5sum
8b9b994dcf57f8f90194d82e234b72ac
- No luck, the hash does not start with a 0… Let's try with nonce=2
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--2" | md5sum
5b7ce5bcc07a2822f227fcae7792fd90
- Still no luck....If we pursue until nonce=16, we get our first leading zero.
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--16" | md5sum
03b80c7a34b060b33dd8fbbece79cee3
- For nonce=208, we get two leading zeroes!
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--208" | md5sum
0055e55df5758517c9bed0981b52ce4a
- Continue like this… If you finally find a hash that has 13 leading zeroes… you're a winner! Other miners will now build upon your block, you've just got 10BTC.
- But you'll have to be fast!
- That's why we need bigger compute and lot of electricity for mining so as to quickly find the nonce value that give us hash value with 13 leading zeros (16 leading zeros in today's Bitcoin blockchain) in this example.
- If someone manages to build a block before you do, you'll have to start again from the beginning with the new block's hash (the one of the winner).
Note: There is no limitation on the rest of the characters of the hash, they could be anything.
Reference: