Understanding Bitcoin Blockchain for Beginners
A Web-2 dev's guide to other Web-2 devs on becoming the cool dev who knows Web3 ššš»
Foreword
Iām a Web-2 dev (React-Native) and recently joined a Web-3 startup (which Iām happy for) where I was tasked to create a Bitcoin wallet in React-Native which was in itself a task which I had no idea about since I did not know Blockchain itself, let alone Bitcoin, for me it was just a crypto-currency. So once I had put in the extra hours and got some clarity on the topic, I thought to create this blog series and explain people these critical concepts in the simplest way possibleš
In this blog, Iāll try to complete a complete summary of how the Bitcoin blockchain works and in the upcoming blogs, weāll dive deep into each topic. So hold on tight and I wish you the best of luck in becoming the Cool Guy who knows Web-3 š»
What the hell is this āBlock Chainā?
Well, itās exactly what it sounds like, a chain of Blocks. What we need to understand is what are these blocks and why are they chained. Simply understand that these blocks store some information and every other block is pointing to the block previous to it, much like a linked list!
Now what information is stored in these blocks is determined by the type of blockchain weāre referring to. In Bitcoin these blocks store a list of the transactions that were done on this blockchain in a certain amount of time and some extra data (Weāll discuss later). In Ethereum, they also contain something called smart contracts (Which are like chunks of code that could be executed on the Ethereum Virtual Machine)
The Bitcoin Blockchain: A Chain of Vaults
As I told you before, the Blocks in the Bitcoin chain contain a list of transactions which typically involve who sent to whom, whatās the amount sent and what was the fees involved. A simple JSON representation of it would look like this
{
"inputs": [
{
"txid": "abc123",
"index": 0,
"scriptSig": {
"signature": "AliceSignature",
"publicKey": "AlicePublicKey"
}
}
],
"outputs": [
{
"value": 0.8,
"scriptPubKey": "BobPublicKeyHash"
},
{
"value": 0.19,
"scriptPubKey": "AlicePublicKeyHash"
}
],
"fee": 0.01
}
Imagine Bitcoin as a chain of vaults, each containing locked assets called bitcoins. These locks signify ownershipāonly the rightful owner can unlock and spend these bitcoins. When you send Bitcoin to someone, you unlock some vaults, create a new lock for the recipientās public key, and broadcast the transaction to the network. Miners then verify that you have the right to unlock the vault and add your transaction to the blockchain.
Now letās understand the same explanation in technical terms
The vaults weāre speaking to are called UTXO which stands for Unspent Transaction Outputs and again, they are exactly what they sound likeš. See in the Bitcoin blockchain, whenever you send someone an amount, we canāt directly send the exact amount as we do in the bank rather we first look at all the Unspent changes left with the sender, take some of them, and send all of them to the recipient, and the amount thatās extra after that is returned to us as yet another UTXO which we can use in our future transactions
Understanding the JSON
Inputs
These are the vaults or the UTXO that youāre using to send the transaction. Each object in the input array signifies a UTXO of a given past transaction.
Transaction Id (txid): The txid
is in little-endian format (The original ID is reversed to keep the least significant bye first) and refers to the hash of the transaction which yielded this change or UTXO
.
index: The index
comes into play when there are multiple UTXOs created in a transaction (arranged as an array) as change, this index helps us to select which UTXO we are using in the transaction.
Script Signature: The scriptSig
helps us verify that weāre the owner of this UTXO, signature
which is created by the sender using their private key (will be explained later promise š¤š») along with their public key (Their public identity on the Bitcoin blockchain) is enough to verify that the person owning the signature is indeed the one in control of this UTXO
Outputs
This is very simple, this field specifies to whom are the bitcoins from the UTXO being sent. Usually, there are 2 objects in that array, the first one conveys the recipient through their publicKey and the amount that will be sent to them. the second object is the āChangeā or the leftover amount that is returned back to the recipient in the form of UTXO
Fees
For every transaction that we do, we have to pay a fee. This fee goes to the person who verifies our transaction and adds it to the Block (called a miner āļøš·š»)
Once the block is verified and added to the chain of blocks, our transaction is successful!
Now letās understand every component in sufficient detail so that you can prepare your next web3 startup pitch š
Components in Bitcoin Blockchain
Now weāll dive into all the components that help us to interact with the Bitcoin blockchain. In upcoming blogs, Iāll deep dive into each of them but Iāll try to keep their explanation as concise as possible here.
Bitcoin Node
The entire Bitcoin Blockchain is just a collection of computers collectively running a software called Bitcoin. These nodes are responsible for always being in sync with the Blockchain and can verify the transactions that are being done on the blockchain network. Think of it like every node has a linked list of Excel sheets which contain the transactions that were done on the blockchain. As soon as a new block or sheet is added, all the nodes sync up and update their local blockchain with the latest change.
Bitcoin Wallet
To interact with the Bitcoin blockchain, you need two keys:
Public Key: Similar to a bank account number, itās shared publicly to receive bitcoins.
Private Key: Like your ATM PIN, itās used to unlock and spend your bitcoins.
Together, these keys form your Bitcoin wallet, managing all bitcoins associated with your account.
Now letās understand how Wallets Are Created
Step 1: Generating a Seed
The process begins by generating a pseudo-random 128-bit number called the seed. A checksum is derived using SHA-256 and appended to the seed, forming a 132-bit value.
Step 2: Mnemonic Generation
This 132-bit data is divided into 12 parts, each 11 bits long, and mapped to words from the BIP-39 word list. These 12 words are your mnemonicāthe key to your wallet. Keep it safe, as anyone with access to it can control your bitcoins.
ā ļøWhat not to do with this Mnemonic Phrase
Paste it on your room (why? just why?)
Save it on your PC as a text file (Really?)
Tell your pet about it (They might take control over your crypto and join Illuminati)
Summon a demon with it (*negotiable*)
ā What to do with your Mnemonic Phrase
Invoke the great spirit of deception and ask it how you can securely store itš§š»(*Optional*)
Jokes aside, be sure to take multiple hard copies and store them in different places so that even if one or more copies are destroyed youāre still having a backup. (Donāt tell anyone about these places, especially if youāre a married guy IYKYK)
Step 3: Creating Master Keys
The seed is passed through the HMAC-512 algorithm, producing a 512-bit output. The left 256 bits form your Master Private Key, and the right 256 bits form the Master Chain Code. Using Elliptical Curve Cryptography (secp256k), your Master Public Key is derived as:
P=kĆG
Where:
k is your private key.
G is a fixed starting point on the curve.
This process ensures security, making it computationally infeasible to derive the private key from the public key.
Using your Master Private Key and Master Chain Code, you can generate multiple child wallets in a tree-like structure (Hierarchical Deterministic Wallets). These wallets are secure because revealing a childās private key doesnāt compromise the parentās private key.
Wallet Address Types - There are a few different types of address that we can create which process transactions differently. Weāll discuss them in a dedicated blog
Legacy (P2PKH): Oldest format; addresses start with
1
.SegWit (P2SH): Optimized version; addresses start with
3
.Native SegWit (Bech32): Widely used; addresses start with
bc1
.Taproot: Uses advanced technology like Schnorr Signatures and Merkle Trees; addresses start with
bc1p
.
Transactions and UTXO
Bitcoin uses a system called UTXO (Unspent Transaction Output) to track balances. Think of UTXOs as leftover change after a transaction. Hereās how it works:
Fetch all UTXOs associated with your wallet.
Define which UTXOs to unlock using your private key.
Specify outputs:
Amount sent to the recipient.
Change returned to yourself.
Caution:
If you donāt specify the change, itās given to miners as a fee!
Mining: The Backbone of Bitcoin
Miners validate transactions and add them to the blockchain. Hereās the process:
Verification: Miners ensure transactions are valid (e.g., you have enough balance).
Merkle Root Calculation: The transactions in the block are in the form of a Hash, Miners Combine transaction hashes into a single hash, the Merkle Root which behaves as a check-sum for that can be used to trace if a particular transaction hash is there in a block or not.
Block Hashing: Create a hash of the block data (transactions + metadata).
Proof of Work: Miners solve a complex puzzle to generate a hash with a specified number of leading zeroes.
This computational effort ensures security and prevents tampering. Once verified, the block is added to the blockchain, and miners receive rewards (block reward + transaction fees).
Key Features of Bitcoin
Decentralization: Operates without central authority.
Security: Uses cryptographic algorithms to ensure tamper-proof transactions.
Transparency: All transactions are public and verifiable.
Scarcity: Only 21 million bitcoins will ever exist.
Limitations of Bitcoin
Scalability: Limited transaction speed (7 Transactions Per Sec).
Energy Consumption: High energy usage due to Proof of Work.
Limited Use Cases: Primarily for transferring value; lacks programmability like Ethereum.
Bitcoin vs. Ethereum
Feature | Bitcoin | Ethereum |
Purpose | Digital Gold | Programmable Money |
Smart Contracts | No | Yes |
Transaction Speed | ~10 minutes/block | ~12-15 seconds/block |
Consensus Mechanism | Proof of Work | Proof of Stake (from ETH 2.0) |
Emerging Technology: Lightning Network
Bitcoinās Lightning Network addresses scalability by enabling off-chain, near-instant transactions. Itās a layer-2 solution for microtransactions and faster payments.
Conclusion
Bitcoin is a groundbreaking technology that redefined how we perceive money and transactions. Understanding its core concepts like keys, wallets, UTXO, and mining can help you appreciate its power and potential. While it has limitations, ongoing developments like the Lightning Network continue to improve its functionality.
Stay tuned for more blogs if youāre excited to dive deeper into Bitcoin or blockchain technology!
Feel free to comment with any doubts or improvements. Iāll be happy if you reach out on my socials and Iād love a follow on Twitter š¦ (Didnāt find this emoji š¦)