Cryptocurrency wallets and exchanges (Article 33)

The first step to interacting with this great technology is understanding how transactions on the blockchain are performed, and the various operations involved.

Al_ref
Decentralized Innovations
7 min readNov 11, 2022

--

Photo by regularguy.eth on Unsplash

At its core, every process on a blockchain is a transaction. It is a record of an exchange between 2 or more parties, and this exchange can be either a record of a transfer of value, e.g., exchanging cryptocurrencies, or a record of a specific operation, e.g., identity verification. To be able to understand advanced blockchain concepts, it is necessary to grasp the basics of blockchain transactions.

Transactions:

Blockchain transaction is an encrypted communication between two parties through the blockchain as an intermediary. For this operation to complete, each party needs 3 items: 1) a private key, 2) a public key, and 3) a wallet address. Those 3 items will be explained in a later article, but for now, here are brief definitions:

  1. Private key: This is an encryption key used to protect information. It can also be used for identification purposes. To explain a complicated process simply, the private key is used to ensure the authenticity of an operation on the blockchain; it, therefore, functions as some sort of a stamp, and if this stamp is put on a transaction, it is proof that the private key owner is the one who put it.
  2. Public key: This is a decryption key used to verify the identity by decrypting the signature of the private key. When a verifier receives a message, they apply the public key of the sender to it and this will result in a stamp being revealed. If this stamp matches the stamp that can be generated by the private key, then this is proof that the message received is genuinely from the sender. The private and public keys are interchangeable, which means that if one key is used for encryption, then the other key is used for decryption and vice versa.
  3. Wallet address: This is a derivative of the public key (while the public key is a derivative of the private key). So, these 3 are linked together and not chosen at random. They are generated through complex mathematical processes that link them together and guarantee security and authenticity.
From private key generate public key, and from public key derive multiple wallet addresses.

With this information clarified, let’s see how a transaction is done on the blockchain.

At the start, every blockchain user-to-be generates a private-public key pair. From this pair, they can generate a wallet address (in fact, they can generate an infinite number of wallet addresses tied to their keys). Once they have those 3 items, they can start interacting with the blockchain.

First, users announce their public keys to the whole network of blockchain users. When a user wants to interact with the blockchain, they write a transaction, which is similar to writing a check. Then, they put their signature on it using their private key and broadcast it to the blockchain network. The blockchain then puts this transaction in a UTXO (Unspent Transaction Output) list. This is a list of all transactions that are signed but not verified yet. Miners check that list and each picks a UTXO to verify. They check the name on the check, pick up the public key of that name and use it to decrypt the signature on the check. If the stamp output of the decrypted signature matches the stamp of the name on the check, this means it is a genuine transaction, so they can add it to the blockchain to be performed (either transfer funds or complete an operation).

Wallets:

A wallet is a software that generates the private and public keys, then from them drives addresses where the cryptocurrencies can be stored. Unlike the wallets we use in real life, cryptocurrency wallets hold no funds. All the funds are held on the blockchain. They are stored in a block and secured by unbreakable encryption. The only person who can access these funds is the owner of the private key that stored those funds on the blockchain. So, a wallet is only an interaction software with the blockchain.

Once a private key is generated, it can be stored in a txt file, written on a piece of paper, or even engraved on a stone. That private key can be used from any other wallet to access the funds. Private keys are very fragile because if they are lost, there is no means of recovering them. And without the private key, any funds on the blockchain will remain trapped there forever.

Crypto wallets have 2 functions: the first is to look at the blockchain and construct UTXOs, and the second function is to sign the transactions. The first function requires no security. No transaction is useful without a signature. However, to avoid forgery, security for the signing function is crucial.

Software wallets are prone to hacks since they live on computers and in order to be able to interact with the blockchain, they are also connected to the internet. This threat to the security of software wallets led to the introduction of hardware wallets. Hardware wallets work in a split manner. The first part is a software stored on the hardware that has the private key and signs transactions offline. The second part is a companion software that separately interacts with the blockchain and constructs transactions. Once the transactions are constructed, the two parts communicate offline where the hardware wallet receives the transactions, signs them, then returns them to the companion software. Once the two parts are disconnected, the companion software gets on the network again and broadcasts the transaction. This way, the private key that is stored on the hardware wallet is protected from being stolen or hacked. With blockchain standards in place, any hardware wallet can work with any companion software.

Software wallets are usually referred to as “hot wallets”, and hardware wallets are usually called “cold wallets”. Similarly, storing the private key in software on a computer or in the cloud is called “hot storage”, while storing the private key offline, either on a hardware wallet or writing on a piece of paper, is called “cold storage”. So contrary to the belief that the cryptocurrencies are hot or cold stored, it is actually the private key that is hot or cold stored, while the cryptocurrencies never leave the blockchain.

Exchanges:

Shortly after Laszlo Hanyecz (alias ‘Laszlo’) purchased 2 pizzas for 10,000 bitcoins, an interest in selling and buying bitcoins for fiat currency surfaced, and bitcoin exchanges became a thing. People had to engage in transactions with anonymous individuals that they did not necessarily know or trust. In Bitcoin, there is no dispute resolution mechanism. This means that if the pizza guy delivered 2 empty boxes to Laszlo, there was no way for Laszlo to retrieve his 10,000 bitcoins.

Since Bitcoin blockchain is not Turing-complete, creating Bitcoin Dapps that operate as an exchange is not possible, which in turn led to the ironic creation of centralized exchanges (CEXs). This spurred out of convenience.

Exchanges work with bid/ask order books. This is where sellers/buyers write down the prices they want to sell/buy at, and once 2 prices are matched the trade gets executed. However, to speed the process and ensure the completion of any trade, exchanges depend on Market Makers (MMs), which is a group of sellers who deposit their funds at the exchange accompanied by the prices they want to sell them at.

Example of order book from Binance.

Liquidity pools:

After the introduction of Ethereum, crypto exchanges transitioned from being centralized to becoming Decentralized Exchanges (DEXs). DEX Dapps operate just like CEXs with order books. However, this proved cumbersome and inconvenient as all transactions must be recorded on the blockchain, which additionally incurred costs to the MMs (these do not exist in CEXs) and the transactions were also relatively slow.

To solve these problems, liquidity pools (LPs) were created. A liquidity pool is a smart contract where any blockchain user can deposit funds. Liquidity providers deposit two cryptocurrencies A and B. This allows other blockchain users to exchange their cryptocurrency A for cryptocurrency B in a process called “swapping”. Liquidity providers are MMs, but they do not incur any costs but rather reap rewards in a process which is called “yield farming”. DEXs charge fees to the swappers to pay for the operation and reward the liquidity providers.

Liquidity pool

The introduction of LPs led to the explosion of DeFi. With a pool of funds available in a smart contract, decentralized trading, lending, and insurance are possible, just to name a few.

After understanding what a blockchain is and knowing the different applications and risks associated with it, the next step is to test the water and try to understand how cryptocurrencies and blockchains work in practice. The first step is to create a wallet. Metamask provides a good start to getting your toes wet in the decentralized world. Since this article is part of an introductory series, it neither includes tutorials for specific wallets or applications nor does it include financial advice to buy, sell or trade cryptocurrencies.

--

--