How cryptocurrencies actually work
By Laura Desmond
A simplified introduction to transactions and ledgers
Prior articles posted described how to build a simple blockchain and how to learn how to code elliptic curve cryptography. This gave the 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.
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:
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.
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!