👩🏼‍💻 A New Developer’s Bullet-Point Guide to Blockchains and Cryptocurrencies (Part 2/4) // Bitcoin

For blockchain programming and economic commentary follow me on 🐦 @0xfmoi.

Now that we’ve got the basics down, let’s take a look at how things actually work on the blockchain. And what better way to do this than to follow a transaction through end to end (of course besides having a go at it yourself — but more on that in Part 3 — More quick blockchain concepts)?

If you haven’t taken a look yet at understanding foundational blockchain principles, check out Part 1 — The bare minimum basics.

This guide is written in 4 parts:

  1. The bare minimum basics (what is blockchain)

  2. Transaction examples (show me the money — tech version) // Bitcoin

    2.1. Transaction examples… // Ethereum
    2.1.1. Transaction examples… // Ethereum // EVM

  3. More quick blockchain concepts

  4. A comparison chart (cheatsheet of 5 top blockchains)

Part 2 — Transaction Examples (Show Me the Money — Tech Version) // Bitcoin

So how do blockchains actually work? Let’s get technical and look at one example of blockchain in action — Bitcoin.

Bitcoin (BTC)
Bitcoin (BTC)

Alice wants to buy a doughnut using BTC. The doughnut costs 100,000 satoshis (the equivalent of 0.001 BTC). Joe the doughnut shop owner asks Alice to scan the QR code that sends a message to Alice’s mobile phone which pulls up her wallet to display the transaction request.

Alice initiates the transaction through her digital Bitcoin-compatible wallet by “signing” the transaction authorising the blockchain to send 100,000 satoshis to Joe. This approval prompts her wallet to send out a message to the Bitcoin blockchain network that she is initiating a transaction from her wallet to the recipient’s wallet address.

Alice’s wallet has a private key (a random 256-bit number) which safeguards its contents. The private key generates a new public key using elliptic curve cryptography producing a new wallet address for each new transaction. This way her private key is kept private from public knowledge but the network knows where the transaction is being initiated from and can interact with her wallet. Private keys that are lost can never be recovered.

Blockchain security typically implements versions of one-way cryptography called hashing algorithms which have two pivotal asymmetric attributes that make them prime tools: (1) these algorithms are easy to employ but their outputs are impossible to reverse engineer (e.g. public key generation) (2) posed values are hard to solve for but easy to verify (e.g. the golden nonce).

Miners at work receive Alice’s wallet’s message and are at work.

Each block on the Bitcoin blockchain is comprised of about 1MB worth of data (typically about 50 transactions). The PoW the Bitcoin network requires is finding the golden nonce (number used only once) of the new block — a 4-byte number which can only be discovered through a series of trial-and-error. This PoW type may also be referred to as a hashcash PoW. An acceptable golden nonce is any nonce value that is less than or equal to the target value. Target value difficulty is adjusted every 2,016 blocks (or one difficulty epoch) based on the length of time it took to mine the previous 2,016 blocks (around two weeks). This is programmed as part of Bitcoin core and calculated formulaically. (In practice Bitcoin’s core code is off by one and calculates for the past 2,015 blocks). Adjusting for the difficulty level means increasing or decreasing the target value which increases or decreases the number of possibilities for an acceptable nonce. The larger the value the easier it is to find the golden nonce because there are more acceptable possibilities.

The new nonce is used to generate the new block header hash value which is unique to this new block and can be used to identify it. Blocks may also be identified through its place in the blockchain. For example, the genesis block or the first block in a blockchain is block #0. This number is consecutively assigned according to the block’s time of creation in the life of the chain. The block hash value is generated by passing the block header parameter values, including the nonce, twice through SHA-256 (Secure Hash Algorithm) encryption. SHA-256 is a practically deterministic function meaning it will practically always distribute the same output when provided with the same input. This helps miners validate these values.

After six confirmations a transaction is considered final and virtually irreversible given the built-in consensus algorithm defences (in this case the insurmountable computation power required to rehash six blocks in a 51% type attack). If a parent block is changed in any way a rehash of the hash value for that block is required since block header variables are enmeshed. Thus any modifications to a block forces a recalculation of all blocks that sit on top of it including said block. As the network is busy running, temporary multiple forks are in flux with different miners building different temporary children blocks with different transactions for the same parent block (the latest confirmed block).

Ashley is a miner in London whose node finds the nonce and computes the puzzle first and has completed a block that also has Alice’s transaction in it. Her work accuracy has been independently verified by the majority of all participating nodes. Ashley is rewarded with BTC for her work. New BTC coins are minted by the blockchain and deposited into her wallet along with the block’s total transaction fees.

Alice’s transaction has now been recorded multiple times on the blockchain. The whole process is usually instantaneous for one confirmation of a low-value transaction, whilst on average it takes about 10 minutes for a Bitcoin transaction to be confirmed (as regulated by the target difficulty).

Transactions on the Bitcoin blockchain are recorded in the form of spent and unspent. UTXO (Unspent Transaction Output) is what Alice sees as her new BTC balance and is the result of her original BTC balance prior to this transaction minus the amount spent and transaction fees taken.

Alice is now down 0.001032 BTC but plus one doughnut. Alice is always able to go onto the Bitcoin network to look back through her transaction history and the status of any new pending transactions.

A just-in-case refresher — what is a bit and what is a byte? A bit is the smallest increment in computer data and is a binary digit of either 1 or 0 (which are the electrical values for on or off in hardware engineering). 8 bits are assembled into a byte. Computers use the binary base-2 numeral system. A kilobyte is 1,024 bytes and a megabyte is 1,024 kilobytes, etc. Bytes are assembled into ASCII (American Standard Code for Information Interchange) codes which represent the English language and some symbols. Machine language or a computer’s native language is binary.

What makes up the structure of a block on the Bitcoin blockchain?

Short note on nodes. Different nodes on the blockchain play different roles.

A light / lightweight node only downloads block headers and does not store the entire blockchain history. Light nodes verify transactions using SPV (Simplified Payment Verification — a wallet client) and acts as an intermediary between the wallet and full nodes.

A full node validates transactions and blocks

A pruned full node downloads blocks from the beginning of the chain and maintains them up to a limit (e.g. 250MB worth) after which it deletes the oldest blocks.

An archival full node hosts the entirety of the blockchain.

  • Mining node — PoW participants.

  • Staking node — PoS participants.

  • Authority node — PoA participants.

  • A master node only verifies but does not add blocks. It may have special responsibilities e.g. governance-related.

And that was a brief introduction to Bitcoin… but what about a second crowd favourite — Ethereum? :) Here we go.

For blockchain programming and economic commentary follow me on 🐦 @0xfmoi.

Subscribe to ella @0xfmoi
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.