Crypto crash course: blockchain, smart contracts, dapps, and more
First deep dive into how crypto operates
If you’re interested in finding out more information about any of the topics I cover, I recommend these two sites:
To understand Bitcoin and Ethereum more deeply, I recommend reading their whitepapers:
Other blockchains also have their own whitepapers, which you can find on their websites.
Happy learning!
-Katja
Crypto crash course: blockchain, smart contracts, dapps, and more
Introduction
Understanding blockchain requires an understanding of its protocols. Protocols are rules on structuring, sending, and receiving information between computers. In crypto, protocols define and establish the blockchain as well as everything built on that blockchain.
Of course, protocols aren’t unique to blockchain. You’re reading this paper on a website with a URL that starts with “http,” which stands for “hypertext transfer protocol.” Protocols form the foundation on which the internet is built and data gets transferred from one computer to another.
Blockchain basics
At its core, a blockchain functions as a database: it stores information (mostly about crypto transactions) across a network of nodes (computers, servers, etc).
Each node contributes to the blockchain system by verifying transactions or storing the entire blockchain or both. The bigger the network of nodes, the more decentralized the blockchain becomes. This decentralized nature allows blockchains to provide a high level of trust and security because no single entity has all the control.
If you have a computer and an internet connection, you can operate a node or access the blockchain. The blockchain system has exceptionally low barriers to entry, with the main one being understanding how it all works.
Different blockchains have different protocols, but their core functionality is very similar. The information blockchains deal with typically involves some type of transaction.
Information gets stored as “blocks.” Each block contains information about recent transactions and a reference to the block that preceded it (forming a chronological sequence of events). When one block gets filled, it closes and attaches (links) to the last filled block, creating a chain (i.e. blockchain). Once the block is closed and added to the blockchain, the updated blockchain gets shared with the entire network.
Therefore, you can think of the blockchain as a timeline of transactions or a ledger.
Before a block closes and links to the chain, it has to get approved ( to prevent fraudulent transactions and double spending). In order to do this, the blockchain employs a “consensus mechanism.” This means that the majority (51%) of all nodes must approve the new block before it can be added to the blockchain.
Consensus mechanisms
Different blockchains use different consensus mechanisms, but two have garnered the most attention: Proof of Work (PoW) and Proof of Stake (PoS). Both Bitcoin and Ethereum use PoW (Ethereum’s upcoming merger will transition to PoS).
PoW requires an individual to solve a complex mathematical puzzle. Without getting too technical, the main part of this puzzle involves finding a random sequence of numbers called a nonce. A nonce is used for authentication purposes (like in two-factor authentication systems).
Finding the correct (Golden) nonce involves pure trial and error, meaning adding something to the blockchain requires a lot of computing power (known as hashrate) and electricity. The higher a node’s hash power, the more likely it will find the nonce and solve the problem.
[If you want to read a more technical explanation of this verification process, see the Appendix section below]
The system also allows individual computers to pool their computing power and split the reward if they solve the problem. As a system of checks and balances, the blockchain adjusts the difficulty of the problem depending on how much computing power is connected to it at that time. This ensures that one node doesn’t dominate.
Finding a solution “proves'' that you did the “work” using computational resources. The process of adding blocks to the blockchain is known as mining, and miners get rewarded with the native cryptocurrency of the blockchain (a Bitcoin miner gets rewarded with Bitcoin).
With Bitcoin, when a miner adds a block to the chain, the new Bitcoin gets “printed” and given to the miner (the miner mints the currency). The amount paid to the miner gets taken out of the supply of Bitcoin not already in circulation. Eventually, when miners have to trade in their Bitcoin for fiat currency to pay for their mining expenses (like electricity or equipment), this Bitcoin enters circulation.
With Ethereum, rewards for mining differ. A participant can submit a request (broadcast) for a transaction. This means that an individual wants to have a transaction verified, executed, and added to the blockchain. When someone broadcasts a transaction request, they must also offer a bounty (some amount of the native currency). The amount of the bounty corresponds to how much time will be required to carry out the computation. This money will be awarded to the miner that will do the work to get the transaction on the blockchain.
On the other hand, PoS came about as a more energy-efficient form of PoW. An individual can offer (stake) their coins for a (random) chance to get chosen to validate the block (becoming a “validator”). The validator fills the block and a specific number of other validators verify it before the block gets closed and added to the chain. This consensus mechanism avoids the competition (and use of excess computing power) experienced with PoW in racing to find the Golden Nonce.
With PoS, miners can pool together capital (staked crypto), instead of pooling together computing power in order to get selected for validating the block. This staking system allows for a governance to emerge over how the blockchain functions. For example, voting on the minimum amount of staked coins to be eligible for selection as a validator.
If a computer tries to break the rules of the blockchain, some of their staked crypto will get destroyed (this process is known as slashing).
Cryptocurrency
Crypto can be thought of as the oil that keeps the machine (blockchain) running. Crypto creates an incentive for maintaining the blockchain by keeping miners committed to verifying and validating transactions. Without a network of miners, the blockchain would not function because there would be no one protecting the system from malicious players.
Although many people think of crypto and blockchain as interchangeable, crypto is really just one (albeit essential) application of blockchain technology.
Smart contracts
A smart contract is a collection of code that executes a certain function and resides on the blockchain (not controlled by a user). Such contracts are defined by and automatically enforce rules via their code, making them self-executing and self-enforcing. Users can interact with smart contracts in order to avoid the use of any intermediary.
The advantages of smart contracts include: accuracy and transparency of transactions, high speed, low cost execution, and more security.
Note an important distinction - All smart contracts are protocols, but not all protocols are smart contracts. Smart contracts have to complete an action. They function through “if/then” statements and can be considered a more macro application of protocols. Protocols don’t necessarily have to dictate an action but can be rules on sending information, storing information, etc.
Smart contracts also interact with other smart contracts. This system becomes the foundation of decentralized applications (dapps).
Dapps
Decentralized applications are blockchain-powered websites that connect participants in a network. They are comparable to phone applications, except there is no central authority governing the dapp, due to their use of smart contracts.
To illustrate this functionality, let's look at decentralized finance (DeFi). DeFi platforms allow lending and borrowing without the use of intermediaries. A lender can enlist their crypto on the platform for lending purposes and earn interest. A borrower can directly take a loan from the platform, repaying the loan with interest at some point in the future. Instead of banks, smart contracts facilitate all these lending transactions.
Dapps are essentially the user interfaces of smart contracts. Although a smart contract can execute these transactions directly, a platform is needed to connect those in a network. For example, there may be lenders and borrowers in a market, but without some platform, how will the lenders ever find the borrowers and vice versa?
Scaling solutions: Layer-1 vs Layer-2
As blockchains become more popular (especially because of DeFi and NFTs), their networks become more congested, meaning transaction speed decreases and transaction costs increase. Scaling means expanding the system while maintaining its integrity (security and decentralization).
Scaling could mean increasing the throughput rate (number of transactions performed per second), increasing transaction speed, and decreasing transaction (gas) fees.
To solve this issue, many solutions have been proposed. Some deal with changing the main blockchain protocols (Layer-1), like incorporating a PoS as opposed to PoW consensus mechanism or incorporating sharding (splitting the main blockchain network into smaller partitions, called “shards,” to minimize the strain on a single network). Others deal with solutions that can help the main blockchain by handling transactions off-chain (Layer-2), like creating new blockchains that are linked to the main one.
There are four types of Layer-2 (L2) solutions, and we’ll briefly cover each one.
Appendix
Bitcoin PoW mining
A block has two elements: the data and the header. The data is the list of most recent transactions. The header represents information about the entire block, making up its “unique identity” and is the part of the block that requires all the computing power to mine.
Before breaking apart the header of the block, here is a visual of the blockchain:
The header contains several pieces of information.
Version of the block
Previous block hash is the hash (reference number for a block in the blockchain) of the block that preceded the new one being created. As mentioned previously, this keeps the chronological order of the blockchain and allows it to build on itself.
Merkle root is a single-line summary of all the transactions in the block. It is created by hashing together pairs of TAXIDs (identification numbers for transactions), which creates a fingerprint for all the transactions in a block. Hashing means taking data, scrambling it (by running the data twice through a function called SHA-256), and producing a unique fixed-length result. See figure below for a visual representation of the groupings that lead to the Merkle root.
Time when block gets mined
Bits is a shortened version of the target, which is a number that the block hash must be below in order to get added to the blockchain. This target adjusts every 2,016 blocks (about 2 weeks), so blocks continue to get mined every 10 minutes (on average). This creates consistency in blocks getting mined and new crypto entering circulation.
Nonce is a random sequence of numbers and is the part of the block that requires the computing power from nodes. Miners must adjust this string of numbers to make the hash of the block header fall below the target (Bits). A nonce can only be used once and, therefore, is used as an authentication protocol by making sure no one can use this blockchain communication to gain future advantage within the system. The first miner to get the correct nonce shares it with the rest of the network and receives a reward (native crypto of the blockchain).
Putting all these concepts together, here is a single block on Bitcoin: