My Journey into Web3: Understanding Blockchain Fundamentals
Introduction
When I first heard about Web3 and the concept of a decentralized internet built on blockchain technology. I was intrigued but also a bit overwhelmed. It quickly became clear to me that before diving into the practical aspects of Web3 development, I needed to understand the fundamental technology that underpins it: blockchain.
What is a Blockchain?
As I began my learning journey, the first question I had was:
What exactly is a blockchain?
Here's what I learned: A blockchain is a decentralized, distributed digital ledger that records transactions in a secure, transparent, and immutable way. It's essentially a chain of blocks, where each block contains a collection of transactions and is cryptographically linked to the previous block.
Wait... What is Cryptography?
As a Web2 developer, I was familiar with concept like encryption and hashing, but the term cryptography in the context of blockchain initially puzzled me. Here is what I learned:
Cryptography is the practice of securing communication and information through the use of codes and chiphers. In the context of blockchains, cryptography plays a crucial role in ensuring the security, integrity, and authenticity of the data and transactions recorded on the network.
Two key cryptographic techniques used in blockchains are:
- Hashing: A has function takes an input of any length and produces a fixed-size output (the hash or digital fingerprint). Even a tiny change in the input data results in a completely different hash output. In blockhain, hashing is used to create a unique identifier for each block, linking it to the previous block in the chain.
- Digital Signatures: Based on asymmetric cryptograpy (public-private key pairs), digital signatures are used to verify the authenticity and integrity of transactions. Users digitally sign transactions with their private keys, and these signatures can be verified by anyone using the corresponding public key, ensuring that the transactions originated from the claimed sender and was not tampered with.
How Does a Blockchain Work?
As I delved deeper, I learned that blockchain networks operate using different consensus mechanisms which are the rules that govern how transactions are validated and new blocks are added to the chain. The two most popular consensus mechanisms are Proof-of-Work (PoW) and Proof-of-Stake (PoS).
PoW, used by Bitcoin and some other blockchains, requires miners to solve complex computational puzzles to validate transactions and create new blocks. The first miner to solve the puzzle gets to add the next block and receive a reward.
On other hand, PoS, used by Etherium and other blockchains. Select validators based on the amount of cryptocurrency they hold (their "stake"). Validators are rewarded for proposing and validating new blocks, and they can penalized for misbehavior.
Joining the Blockchain Network
One of the questions that puzzled me initially was:
How do users join a blockchain network?
And after finding several resources, I learned that there's no need to register or install any specific app to join a public blockchain network like Etherium or Bitcoin. Instead, users need to run a node software (like Geth for Etherium or Bitcoin Core for Bitcoin) on their computer device. This node software connects to the existing network of nodes and download a copy of the entire blockchain data, allowing the node to participate in validating transactions and blocks.
For those who simply want to interact with decentralized applications (dApps) or send/receive transactions, they don't need to run a full node. They can use a lightweight wallet (like MetaMask) that connects to the network through remote nodes run by providers like Infura or Alchemy.
Data Storage on the Blockchain
As I learned about data storage on the blockchain, I started to compare it with traditional databases like MySQL or PostgreSQL that I was already familiar with. Blockchains primarily store transaction data, which includes details like the sender, recipient, amount and any additional data (like smart contract code or data, I will explain more about this in separate article). This data typically stored in a compact binary format optimized for storage and transmission.
However, smart contracts on Ethereum can store and manipulate various data types, including strings, integers, booleans, arrays, and even complex data structures like structs and mappings. Developers can encode data in various formats (like JSON) and store it in the blockchain through smart contract functions or transactions.
What suprised me the most was that blockchains are designed to be append-only data structures, meaning that:
New data can only be added and existing data cannot be modified or deleted directly
And to handle data modifications or deletions, new transactions are created to "undo" or negate the original transactions, effectively updating the latest state of the data.
Comparison with Traditional databases
Coming from a background in Web2 Development, I naturally started to comparing blockchains to traditional databases. While they both server the purpose of storing and managing data, they have fundamentally different architectures, principles, and mechanisms.
Traditional databases
In traditional databases, data is typically stored on physical hard disks or solid-state drives(SSDs) connected to a centralized server or cluster of the servers. The data is stored and organized into tables with rows and columns, following a predefined schema. Transactions are handled through a centralized database managemetn system (DBMS), which ensure data integrity and consistency. Data can be updated, modified, or deleted (depending on access permissions).
Blockchain databases
In contrast, blockchains don't rely on a centralized storage system like hard disks or SSDs. Instead, the data (transactions, smart contract code, and other data) is stored in are decentralized manner across the network of nodes participating in the blockchain. This means that the entire blockchain data is replicated across thousands or even millions of nodes worldwide, eliminating the need for a centralized storage infrastructure.
The decentralized storage mechanism of blockchains has several advantages:
- Fault Tolerance: Since the data is replicated across multiple nodes, the failure or removal of a few nodes does not impact the overall availability and integrity of the blockchain data.
- Cencorship Resistance: With no central authority controlling the storage, it becomes extremely difficult to censor or modify the data stored on the blockchain.
- Data Permanence: Once data is recorded on the blockchain, it becomes practically immutable, ensuring a permanent and auditable record of all transactions and data changes.
However, this decentralized storage approach also comes with challenges, such as the significant storage requirements for each node, as they need to store the entire blockchain data. Additionally, as the blockchain grows in size, syncing new nodes with the existing data can become increasingly difficult and resource-intensive.
To adress these challenges, some blockchain networks employ techniques like pruning (removing older, historical data from nodes) or sharding (dividing the blockchain data across different sets of nodes) to reduce the storage and computational requirements for individual nodes.
Conclusion
So that's it! This is a piece of information that I gather while learning about Web3 from many resources. Now I'm a bit confident and don't need to scared anymore when someone mentioned or said about the Blockchain or Web3 words. A little progress is still a progress isn't it?!. And the next part is, I will try to create a diagram to describe how this blockchain is implemented on a technical side.