Transactions in Blockchain — The nitty-gritty
The purpose of Blockchain was to create an open and borderless system where trust is established through power of network.
Everybody who is a part of the bitcoin network has access to the Blockchain ledger that keeps track of the history of transactions; this is nothing but keeping a track of the Bitcoin ownership changes.
It’s interesting to observe how account balances are kept track of in this network. One cannot simply open the Blockchain to find a line item that says ‘so and so person has X Bitcoins’. The account balances are kept track of through unspent transactions.
Each transaction can be used only once post which it becomes void and hence cannot be used again. This is one way how double spend is avoided.
If I have to find out how many Bitcoins I have in my wallet, I’d have to skim through the entire Blockchain to identify all my transactions. These transactions could have credit and debit — bitcoins sent to me and bitcoins that I have spent. A summation of the unspent transactions gives me the wallet balance.
Following is a snippet of how the transaction log would look like,
Let’s take an example of a transaction between 2 people to understand how the transactions are validated and added to the ledger.
Mark wants to send 5 BTC to George. The following are the different steps before the transaction is confirmed and added to the ledger,
1. Mark would broadcast this message saying he wants to send 5 BTC to George. This is called the transaction message
2. In the world of banking, Mark would need George’s account id, IFSC code etc. as inputs before he could initiate the transaction. In the bitcoin world, Mark would need four things — a private key, transaction message, a public key and the transaction numbers of his unspent bitcoins
a. Whenever a person enrolls in the Blockchain, he gets a private key and public key. Private Key is analogous to the password and Public Key is the ‘To Address’ in the transaction. Essentially the keys are what is being stored in wallets and not money as the keys help in accessing the money
3. Whenever a transaction initiated, it has to be signed with a Digital Signature which is what unlocks the list of unspent funds for the sender and it helps the miners validate that Mark is indeed Mark and not a bloke who claims to be Mark
a. The digital signature is a cryptographic combination of the transaction message and private key
b. This means the digital signature keeps changing for every transaction as the transaction message keeps changing and hence it is difficult to forge a digital signature
c. Through complex math, this digital signature would let the miners know that Mark is indeed Mark. It basically serves as an intermediary that proves that the owner is indeed in possession of a private key without having to look at the private key
d. Also since each node has to verify the digital signature to add that in their ledger and pass it on, the message down the line cannot change as it would end up invalidating the digital signature as it is a function of the transaction message thereby ensuring the message is consistent throughout the chain
4. To spend money, Mark has to provide proof that he has the sufficient funds to carry out the transaction. He has to prove that he is the owner of the public key in which he received money (somebody else would have sent him or somehow he would have gotten money) and the transaction numbers would ensure that the bitcoins with him are unspent. Miners use Mark’s digital signature in a different mathematical function to see if the funds correspond to Mark’s public key (the one in which he received money earlier) thereby validating if he has the sufficient money to carry out the transaction
5. This is how the Miners validate transactions and add them to the ledger and as an incentive they get a nominal amount for doing so
6. If Mark enters the wrong Public Key (to address), then those Bitcoins are permanently lost and hence care must be taken while inputting the right address
7. Also, If one loses their private key then they cannot carry out transactions at all and the bitcoins that they may possess is lost forever
There are several transactions that take place at similar times and the miners validate those transactions and add them to the block. The block size when introduced was 1mb and would essentially contain bunch of transactions together. This is called mining and the block keeps growing in link rising to the term Blockchain. Essentially the block contains the history of transactions and transactions are nothing but ownership changes.
Let us consider a scenario where Mark wants to send George 5 BTC. In the past, Mark has received 3 BTC from Nick (Txn ID — Txn1234) and 3 BTC from Karen (Txn ID — Txn4792) which makes it a total of 6 BTC. The way this would be carried out is
- Mark would input George’s address with a transaction amount of 5 BTC
- Mark would then input his own Public Address and other credentials with a transaction amount of 1 BTC
This is because Mark had 6 BTC and wanted to send only 5 BTC to George thereby transferring the change in the transaction to himself which would also be recorded as a transaction and added to the block.
This is pretty much how two people transact using bitcoins and Blockchain and how the decentralized network processes the transaction ensuring seamless delivery and tamper proof system.
Up next — How Blockchain avoids double spend.