DEV Community

Rishabh Gupta
Rishabh Gupta

Posted on

Another Cryptocurrency post


In this post I'll share some cryptocurrency concepts. It's an explanation post so we won't dive into code and keep it as general as possible.
We start by a basic concept of passbook: When we do any bank transaction it is recorded in our passbook, it holds all the history to our spendings and earnings.
Passbook is a form of simplified ledger. We start by taking a simple example.

Two friends' example

Now we take two friends A and B who want to transfer fake money to each other but instead of printing their own money they do one thing, they create a shared passbook. This shared passbook stores records of both of them. A transfers money to B by adding a record in his own version and he tells B about his transaction, now B can record that transaction too.
This shared record is a distributed ledger, the basis of blockchain.

Shared ledger

Now more people want to trade with them using this fake money so everyone gets that shared passbook. When someone transfers money they inform everyone that they have done so, so that everyone updates their ledger.

Q1 : Where did the starting money come from ? Ans, The game of dice.

Initially, A and B agreed that they will play dice and whoever gets a bigger number will have 10 fake currency. This is also added to ledger.
They agree to do this every hour and hence someone collects 10 fake currency every hour.
Later, anyone who has the ledger has the right to play the game of dice.

This is a basic crypto currency mining scheme. If a lot of people are competing the game of dice is not feasible, hence they are given a problem to solve. Whoever solves the problem first is given the money.

The beauty of this structure is that there is no actual physical notes or any type of asset exchange, it is just a series of transactions.

Q2 : What if someone starts to cheat ?

Let's say B got greedy and wanted extra money, so he added a transaction from A to himself and told everyone A has done so.

To prevent this they agreed to add a signature to the transaction. Much like a signature on the cheque, this acts as a proof telling that the transaction was done by the person himself. Now, B cannot copy A's signatures hence, he cannot create that transaction. Every node checks the signature before adding the transaction to their ledger.

Q3 : Spending money more than once !

This time B got creative at cheating, he had 10 currency at a point in time and he sent that to both A and C. He told everyone (except C) that he sent money to A, and he told C that he sent that money to C. C thought the transaction was a success.

This is the problem of double spending. To prevent double spending participants need a way to differentiate between confirmed and unconfirmed transactions. This is achieved through block chains.

Double Spending

Q4: What is a block chain ?

Block : It is a collection of transactions and contains a hash of the previous block. (hash is a unique number corresponding to a block)

This is similar to linked lists ! Where each block is a node and it's hash is a type of reference.

Every block corresponds to a problem which needs to be solved. This is the mining problem discussed in previous section. Answer of this problem is the hash of the block which is added to the next block. Only a single block is being solved at any point in time.

After a block is solved the transactions it contains are confirmed.

Now no one can change the transaction as this will change the block, which will change the problem and the answer to that problem, causing a chain reaction where the block next to it will change and so on.

Block chain

Extra Reading:

  1. I find Bitcoin wiki a great resource to understand more concepts.
  2. Bitcoin block explorer for taking a look around.

Discussion (0)