Understanding blockchain transactions

In the previous article, we discussed hashing, asymmetric encryption, and digital signatures. In this article, we will dwell on how blockchain transactions work.

An easier way to learn how blockchain transactions work is by following an example. Let’s say I want to buy a book from an online bookseller. The book costs 1 bitcoin (that’s an extortionate price, I know, but this helps us keep our example simple). Now, let’s see how I can perform a blockchain transaction to buy this book.

Traditional Transactions vs. Blockchain Transactions

In real life, we have currency notes and coins of a fixed value. In Sri Lanka, we have 20-, 50-, 100-, 500-, 1000-, and 5000-rupee notes and 1-, 2-, 5-, and 10-rupee coins. We perform transactions by transferring these notes and coins from one person to another. A similar thing happens in blockchain but with a small twist—the notes can take any value. It’s confusing, I know. So, let’s consider this example. For a moment, let’s forget currency notes, go back by a few centuries and use gold as money. Let’s say I have 1kg of gold and want to buy a mobile phone worth 200gm of gold. I can cut off 200gm of gold from the 1kg of gold I have and exchange it for a mobile phone from the seller.

Splitting Value

Instead of doing this cutting business ourselves, let’s have a specialized business do it. Let’s call this business Gold Brokers. This business takes care of cutting gold and sending the right chunks to the right party. We can give our 1kg of gold to Gold Brokers, and have them cut and send 200gm of it to the seller of the phone. So, what happens to the remaining 800gm of gold? Well, Gold Brokers will send that back to me.

Combining Values

Now, let’s say I design a logo for a startup and charge 300gm of gold for it. The startup owner would send 300gm of gold to me through Gold Brokers. So now, I have one 800gm chunk of gold and another 300gm chunk of gold. Let’s say I want to go for broke and invest in real estate. There is a plot of land worth 1kg of gold for sale and I want to buy it. I have 1.1kg of gold but the problem is that they are in two different chunks. Why are they in two different chunks? Because I got them through two different transactions.

But that’s okay. We can now send both chunks to Gold Brokers. They can combine chunks of gold just as they can split a chunk of gold. So, they will meld the two chunks together and then split them into a 1kg chunk and a 100gm chunk. They will send the 1kg chunk landowner and send the 100gm chunk to us.

This is pretty much how blockchain transactions work. Now, let’s get back to our initial example—I want to buy a book for a bitcoin. To spend a bitcoin, I should already have a bitcoin. However, let’s assume that the bitcoin is not in a single chunk. Let’s say I have one chunk worth 0.75 bitcoin and another worth 0.4. So, in total, I have 1.15 bitcoins. What the two chunks of bitcoins imply is that I have obtained them through two different transactions to my account.

Using public keys to generate bitcoin addresses

But how do I prove that I own these bitcoins? Unlike gold, which is tangible, bitcoins don’t actually exist in reality. The fact that I have earned 1.15 bitcoins through transactions is just a record in a ledger. So, how do I prove that the bitcoins actually belong to me and I can spend them? If it is gold, I will be possessing it. But in bitcoins’ case, how can I prove ownership?

Here is where public-key cryptography comes into play. Every account in a blockchain will have a public-private key pair. We use the public key to create an address for an account. Let’s see how we do that.

First, we hash the public key. We call this hash a pubkey hash. We hash the public key since it makes the address shorter as the hashed value is shorter than the actual public key. Moreover, hashing is also said to be used to conceal the public key as a preemptive measure against unprecedented security problems that may allow the reconstruction of the private key from the public key at some point in the future.

We then combine the pubkey hash with an address version and a checksum to help detect errors and then base58-encode it to produce the blockchain address. This address is the one that is publicly shared to get money transferred to one’s account. Besides, this can also be encoded to other formats such as QR codes.

We can use this address to prove ownership. We shall see how this is done in the next article.

1 Comment

Leave a Reply