In the three previous posts we went over the following:
1) The logo of the coin (important)
2) The algorithm for the creation of the “Wallet”.
3) What is a Hash. And the SHA256 hash.
4) What is the Block Chain. Its importance and role.
5) The Billcoin transactions.
6) How to create a new transaction.
In this part we’ll create together the algorithm necessary for “Mining”.
What is Mining?
The reason why Bitcoin became a hit and was fundamentally different than all of the previous crypto-currencies is Mining.
Mining, made it possible to make this distributed p2p currency possible. So what is mining?
It is the process of adding a new Block in the Block Chain. We mentioned in Part 2 that Blocks are nothing else than a small box with transactions. As a miner you follow these steps:
1) Grab a bunch of transactions that are floating in the network. To send a new transaction to the Bitcoin network you send your transaction request to a peer and that is re-transmitted to the whole network. So eventually a person that is “mining” grabs your transaction and adds it in a new block he will mine.
2) Create a “coinbase” transaction. This transaction is nothing else than sending 25 Bitcoin to your own account. This way you have a reason to mine and the economy grows.
3) Find the magic number which is the “nonce” value. A Block consists of the following values as you can see at the following real Bitcoin Block.
The most important ones for us are the Version, Previous Block Hash, Merkle Root, Timestamp, Bits and Nonce.
Let us double_sha256 hash the Version, PrevBlock, Merkle Root, Timestamp and Bits. Double Sha256 used in the Bitcoin is a procedure where the bits of each value are reversed, hashed twice with the sha256 hash and reversed again.
double_sha256(version + prevBlock + merkleRoot + timestamp + bits) = base_hash
Now we have to find the nonce value where double_sha256(base_hash + nonce) = (a hash where the first 16 digits start with 0).
So on the top block double_sha256( 02000000 + 0000000000000000adc3ac7bba70b5af20e2c121cf536e34e517556a4130007e + 27c4a3ec6991f841c3b72882f9aae5ba8eb4709df0e7d4779a6c38e4eb94b071 1396890405 + 419476394 + 3539232563 ) = 0000000000000000182b74160318696df007c060d7c24a0dba7e359ad1364971
That is it! Once you’ve found the nonce you can send the new block to the network. So now each transaction is in the block and the block is in the blockchain. The next block now should use the hash of the last one as the prevBlock value and a new nonce to create a new hash value. You can checkout the next block created below:
So the flow is
1) Create transaction and send it to the network
2) Someone that is “mining” will catch it add it in a new block and find the new nonce to add that block in the blockchain.
A last point that should be made is that by making it hard to add a new block in the blockchain you secure the economy. Because each time someone else will find the nonce and you distribute the effort needed to add transactions in the blockchain. Also, it becomes random which democratizes the procedure as you never know who will manage to mine first.
You can checkout now Step 4 in the Billcoin economy over here => http://bstavroulakis.com/demos/billcoin/ and start Mining to generate some Billcoins!