paint-brush
How cryptocurrencies actually workby@schaetzcornelius
679 reads
679 reads

How cryptocurrencies actually work

by Cornelius SchätzSeptember 27th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In my last two articles <a href="https://medium.com/coinmonks/build-a-simple-blockchain-fe7ee48090d9" target="_blank">Build a simple Blockchain</a> and <a href="https://medium.com/coinmonks/learn-how-to-code-elliptic-curve-cryptography-be646d2c9757" target="_blank">Learn how to code elliptic curve cryptography</a> I gave you a step by step guide on how to implement some basic functions of <a href="https://hackernoon.com/tagged/blockchain" target="_blank">blockchain</a> <a href="https://hackernoon.com/tagged/technology" target="_blank">technology</a>. I would kindly recommend to read those articles first before you turn to this one. You may have learned, that blockchain is a decentralized and cryptographically secured database. In this decentralized network any participant has an address, that we called the <em>public key</em>, which is strongly connected to something called <em>private key</em>. The data stored in a blockchain can be anything, but in most cases, those datasets are transactions. This is where we get to cryptocurrencies — a cryptocurrency is just a blockchain network, whose data are transactions. In this article, I would like to dig a little deeper into this field and show you how cryptocurrencies actually work.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - How cryptocurrencies actually work
Cornelius Schätz HackerNoon profile picture

Image Source

A simplified introduction to transactions and ledgers

In my last two articles Build a simple Blockchain and Learn how to code elliptic curve cryptography I gave you a step by step guide on how to implement some basic functions of blockchain technology. I would kindly recommend to read those articles first before you turn to this one. You may have learned, that blockchain is a decentralized and cryptographically secured database. In this decentralized network any participant has an address, that we called the public key, which is strongly connected to something called private key. The data stored in a blockchain can be anything, but in most cases, those datasets are transactions. This is where we get to cryptocurrencies — a cryptocurrency is just a blockchain network, whose data are transactions. In this article, I would like to dig a little deeper into this field and show you how cryptocurrencies actually work.

Keeping track of the funds — Account based ledger system

There are two possible ways, that are used in blockchain technology, to keep track of the funds a participant in the network has. The system used by the Bitcoin network is the so called Transaction based ledger. I will focus on this one in another article. The most intuitive one to use is the Account based ledger. In this system, simply spoken, each user has got an account with the following properties:

account = {publicKey, Funds}

So the account is a dataset containing the public key of the user and his or her funds. Each account that exists is stored in the blocks of the blockchain. The funds are updated with every block being generated. If a user wants to transfer some of his coins to another public key, he generates a transaction. A transaction is a dataset containing the following information:

transaction = {sender, recipient, funds, signature}

The variable sender stands for the public key of the sender of funds, the variable recipient for the public key of the one receiving coins. The variable funds refers to the amount of coins being transferred. The signature is generated using elliptic curve cryptography and proves that the private key is indeed being owned by the one sending the coins. If you are not familiar anymore with this procedure, have a look again at Learn how to code elliptic curve cryptography. As soon, as a transaction data set is in the latest block of the blockchain, the funds have been officially transferred. The structure of a block in an account based ledger system may look like this:

Simplified structure of a block in a blockchain used for cryptocurrency purposes.

The transactional data is a list (indicated by []) of data sets (indicated by {}). Each transactional data set contains the public key of the sender, the public key of the recipient, the amount of funds being transferred and the signature of the sender. The account data is a list of accounts, where each account is a dataset only containing a public key and the amount of funds.

Transactions in the network

After a user generated a transaction, he sends this dataset to the whole network to have it validated. This is how it should be in the theory. The actual case is a network consisting of something called full nodes and light nodes. Those full nodes are network participants, that collect transactional data sets, validate them and add them to the block they are generating. The light nodes are just users of the network, that send and receive funds. So the light node, that generates a transaction, sends the transactional data set to the full nodes, that have it then validated.

The validation procedure requires the full node to see if the signature is valid and if the amount of funds, that the sender actually has in his wallet, is sufficient to transfer the coins. Therefore he gets the last block of the blockchain and looks for the account with the public key of the user to check if the value of owned funds is at least as high as the value of the funds being transferred. If the signature and fund check yield a positive result, the account s of both the sender and the recipient are being updated and the transaction added to the newest block. After the one network participant, who is actually generating the block, has collected enough transactions, he sends out the block to everyone in the blockchain. The other network participants check the data in the block and their validity. After being accepted by every node, the blockchain is therefore being updated and the funds transferred. The procedure of transferring funds is visualized in the figure below.

Visualization of how a transaction works in a blockchain network.

So now you may have understood the basics of how the transaction of cryptocurrency coins using blockchain technology works. In one of the following articles, we are going to code a little account based ledger system.

I hope you liked reading this little introduction to how cryptocurrencies actually work. If so, leave some claps here and thank you for reading!