0% found this document useful (0 votes)
8 views15 pages

Block Chain FinalNotes

The document provides comprehensive notes on Bitcoin and Hyperledger Fabric, detailing Bitcoin wallets, storage methods, and the differences between hot and cold storage. It also contrasts permissioned and permissionless blockchains, focusing on Hyperledger Fabric's modular design and smart contracts. Additionally, it covers Ethereum's architecture, including its accounts, transactions, and the Ethereum Virtual Machine (EVM).
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views15 pages

Block Chain FinalNotes

The document provides comprehensive notes on Bitcoin and Hyperledger Fabric, detailing Bitcoin wallets, storage methods, and the differences between hot and cold storage. It also contrasts permissioned and permissionless blockchains, focusing on Hyperledger Fabric's modular design and smart contracts. Additionally, it covers Ethereum's architecture, including its accounts, transactions, and the Ethereum Virtual Machine (EVM).
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Blockchain Final Notes by Haris Ahmed

Bitcoin Wallets and Storage

What is Bitcoin Storage?

Storing Bitcoin means safely managing private keys, which are secret codes to access and spend your Bitcoin. Focus on
three goals:

• Availability: Use your Bitcoin anytime.

• Security: Prevent others from stealing your Bitcoin.

• Convenience: Make key management easy.

Simplest Way to Store Bitcoin

• Store your private key in a file on your computer or phone.

• Pros: Convenient, accessible as long as you have your device.

• Cons:

o Lose your device or wipe it? Your key and Bitcoin are gone.

o Device hacked? Your key could be stolen, and so could your Bitcoin.

Wallet Software

• Wallet software manages your Bitcoin and keys with an easy interface.

• Shows your Bitcoin balance and simplifies sending/receiving transactions.

• Available as apps on phones or computers.

Choosing a Bitcoin Wallet

• Choosing a wallet depends on your needs and expertise.

• Bitcoin wallets are actively developed with many options based on platform.

Types of Bitcoin Wallets

• Desktop Wallet

o Runs on your computer.

o First type of Bitcoin wallet, offers lots of features and control.

o Ideal for experienced users.

• Mobile Wallet

o Runs on smartphones (iOS/Android).

o Most common, great for beginners, easy for daily use.


• Web Wallet

o Accessed via a web browser, keys stored on a third-party server.

o Convenient but less secure due to third-party reliance.

• Hardware Wallet

o Physical device (e.g., USB) for secure key storage.

o Connects via USB or NFC to your computer/phone.

o Very secure, great for long-term storage.

• Paper Wallet

o Keys printed on paper (or etched on wood/metal).

o Secure for long-term storage, but you must protect the physical copy.

o Risk: Losing or damaging it means losing your Bitcoin.

• Brain Wallet

o Keys created from a memorized passphrase.

o No physical storage needed.

o Risk: Weak passphrase can be guessed, leading to stolen Bitcoin.

Wallet Comparison

• Desktop: High control, less convenient, needs secure computer.

• Mobile: Convenient, great for daily use, device security matters.

• Web: Easy but less secure due to third-party control.

• Hardware: Very secure, less convenient for frequent use.

• Paper: Secure for long-term, protect the physical copy.

• Brain: No storage needed, risky if passphrase is weak.

Bitcoin Exchanges

• Platforms like Coinbase, BTC, and Bitfinex for buying, selling, and storing Bitcoin.

• Offer built-in wallets but risky for large amounts since they control your keys.

Bitcoin ATMs

• Machines to buy/sell Bitcoin with cash or cards.

• Convenient but may have high fees.

Hot vs. Cold Storage

• Hot Storage: Keys stored online (e.g., phone/computer). Convenient, less secure.

• Cold Storage: Keys offline (e.g., paper/hardware wallets). Secure, less convenient.
Full Wallet vs. Thin Wallet

• Full Wallet (e.g., Bitcoin Core):

o Stores the entire blockchain (all Bitcoin transactions).

o Needs over 100 GB storage, takes days to sync.

o Offers full control and independence.

• Thin Wallet (Lightweight Client):

o Doesn’t store full blockchain, only needed data.

o Ideal for phones/tablets with limited storage.

o Faster, easier, but relies on other nodes.

Bitcoin Core Interface

• Bitcoin Core: A full wallet software.

• Features:

o Send Transactions: Send Bitcoin easily.

o Receive Transactions: Generate addresses to receive Bitcoin.

o Transaction Tab: View transaction history.

• Powerful but needs storage and technical knowledge.

Wallet Technology

• Wallets don’t hold Bitcoin; they hold private keys to access Bitcoin on the blockchain.

• The blockchain is the public record of all Bitcoin transactions.

• Think of a wallet as a keychain.

Types of Wallets (Key Management)

• Nondeterministic Wallet (JBOK - Just a Bunch of Keys)

o Keys are randomly generated, unrelated to each other.

o Harder to manage, must back up each key separately.

• Deterministic Wallet

o All keys come from a single seed (master key).

o Recreate all keys with the seed.

o Hierarchical Deterministic (HD) Wallet: Keys in a tree structure, easier to manage.


Bitcoin Network

• Bitcoin runs on a peer-to-peer (P2P) network over the internet.

• No central server or authority—fully decentralized.

• Like BitTorrent for file sharing, it’s resilient and open.

Node Types and Roles

• A Bitcoin node is a computer running Bitcoin software with roles:

o Routing: Shares data with other nodes.

o Blockchain Database: Stores transaction history.

o Mining: Creates new Bitcoin, verifies transactions.

o Wallet Services: Manages keys and transactions.

Full Node

• Stores the entire blockchain (all transactions).

• Independently verifies transactions without relying on others.

• Needs over 100 GB storage, 2-3 days to sync.

• Offers maximum independence.

• Most nodes (75%+) run Bitcoin Core.

SPV Node (Simplified Payment Verification)

• Lightweight nodes for phones/tablets.

• Downloads only block headers, uses 1,000x less storage than full nodes.

• Relies on other nodes for transaction data.

• Faster, easier, but less private.

SPV Node Privacy

• SPV nodes have weaker privacy than full nodes.

• Full nodes receive all transactions, hiding which addresses you use.

• SPV nodes request specific transactions, possibly revealing your addresses.

• This reduces owner privacy.

Bloom Filters

• Improve SPV node privacy.

• SPV nodes use Bloom filters to request transactions without revealing exact addresses.

• A probabilistic filter describes what you want vaguely.

• Not perfect: Attackers monitoring traffic might guess your addresses over time.
Extended Bitcoin Network

• Includes all nodes (full/SPV), exchanges, and ATMs.

• Forms a global, decentralized Bitcoin system.

Conclusion

• Bitcoin storage focuses on managing private keys for availability, security, and convenience.

• Wallets include desktop, mobile, web, hardware, paper, and brain, each with trade-offs.

• Hot storage is convenient but less secure; cold storage is safer but less accessible.

• Full wallets store the entire blockchain; thin wallets are lightweight for mobile devices.

• Bitcoin’s P2P network is decentralized with full nodes (independent) and SPV nodes (lightweight, less private).

• Bloom filters help SPV nodes maintain some privacy.

• Understanding these helps you use Bitcoin securely and effectively!


Hyperledger Fabric and Blockchain

What is Hyperledger Fabric?

• Hyperledger Fabric is an open-source, enterprise-grade permissioned blockchain platform.

• Built under the Linux Foundation.

• Highly modular and customizable for business needs.

• Supports smart contracts (called chaincode) written in common programming languages like Java, Go, and
[Link].

• Uses pluggable consensus protocols, meaning you can choose how the network agrees on transactions.

• Doesn’t need a cryptocurrency (like Bitcoin) for mining or running smart contracts, making it cost-effective.

Hyperledger Fabric vs. Ethereum

• Permissionless Blockchains (e.g., Ethereum):

o Anyone can join, and participants are anonymous.

o No trust between users, so they use a mined cryptocurrency (like ETH) to secure the network.

o Relies on heavy computing (mining) to maintain trust.

• Permissioned Blockchains (e.g., Hyperledger Fabric):

o Only known, identified, and often vetted participants can join.

o Operates under a governance model for trust.

o Uses Crash Fault Tolerant (CFT) or Byzantine Fault Tolerant (BFT) consensus, which is faster and
doesn’t require mining.

Permissionless vs. Permissioned Ledger

• Permissionless: Open to all, anonymous, uses cryptocurrency for security (e.g., Ethereum, Bitcoin).

• Permissioned: Restricted to approved members, trusted, no cryptocurrency needed (e.g., Hyperledger Fabric).

Modularity in Hyperledger Fabric

• Fabric’s modular design lets you customize parts of the system:

o Ordering Service: Decides the order of transactions and sends blocks to peers.

o Membership Service Provider (MSP): Manages identities using cryptographic keys.

o Gossip Service (optional): Shares blocks between peers.

o Endorsement and Validation Policies: Rules for approving transactions, customizable per application.

o Smart Contracts (Chaincode): Run in isolated environments (e.g., Docker) for security.

Pluggable Consensus

• Fabric’s consensus (how the network agrees) is modular, so you can choose the method based on your needs.

• Supports Crash Fault Tolerant (CFT) (handles system crashes) or Byzantine Fault Tolerant (BFT) (handles
malicious actors).

• No need for energy-intensive mining, unlike permissionless blockchains.


Hyperledger Fabric Model

• Assets: Anything of value, like real estate (tangible) or contracts (intangible).

• Chaincode: Software defining assets and rules for updating them (the business logic).

• Ledger: A secure, tamper-proof record of all transactions.

• Features:

o Privacy: Keeps data private between specific participants.

o Security & Membership: Ensures only authorized users access the network.

o Consensus: Agreement on transactions without mining.

Smart Contracts (Chaincode)

• Chaincode is a trusted program that runs on the blockchain.

• Defines how assets are managed and transactions are processed.

• Key points:

o Multiple smart contracts can run at the same time.

o Can be added or updated dynamically.

o Treated as untrusted (potentially malicious) for safety, so they run in isolated environments (e.g.,
Docker).
Ethereum Platform

Introduction

• Vitalik Buterin conceptualized Ethereum in November 2013.

• The critical idea proposed was the development of a Turing-complete language.

• This concept is in contrast to Bitcoin.

• Bitcoin scripting language is limited in nature and allows necessary operations only.

• The first version of Ethereum, called Olympic, was released in May 2015.

• Formal specification of Ethereum has been described in the yellow paper which can be used to develop
Ethereum implementations.

Bitcoin vs Ethereum

• Bitcoin

o The “Gold Standard” of blockchains.

o Asset: bitcoins.

o Simple and robust.

o Stack-based, primitive scripting language, not Turing-complete.

o UTXO-based.

o Will likely remain Proof-of-Work.

• Ethereum

o Smart Contract Blockchain Platform.

o Asset: ether.

o Complex and feature-rich.

o Turing-complete scripting language.

o Account-based.

o Planning to move to Proof-of-Stake.

o Block creation time: 15 seconds (Bitcoin: 10 minutes).

Ethereum Blockchain

• Ethereum can be visualized as a transaction-based state machine.

• The core idea is that in Ethereum blockchain, a genesis state is transformed into a final state by executing
transactions incrementally.

• The final transformation is then accepted as the absolute undisputed version of the state.
Ethereum Network

• Mainnet

o Mainnet is the current live network of Ethereum.

o The current version of mainnet is Byzantium (Metropolis).

o Its chain ID is 1.

• Testnet

o Testnet is also called Ropsten and is the widely used test network for the Ethereum blockchain.

o This test blockchain is used to test smart contracts and DApps before being deployed to the production
live blockchain.

o Other testnets include Kovan and Rinkeby which were developed for testing.

• Byzantium Releases

• Private Net

o This is the private network that can be created by generating a new genesis block.

Components of the Ethereum Ecosystem

• The Ethereum blockchain stack consists of various components.

• There is the Ethereum blockchain running on the peer-to-peer Ethereum network.

• Ethereum client (usually Geth) that runs on the nodes and connects to the peer-to-peer Ethereum network
from where blockchain is downloaded and stored locally.

• Another component is the [Link] library that allows interaction with the Geth client via the Remote Procedure
Call (RPC) interface.

Various Elements in Ethereum Blockchain

• A formal list of all high-level elements present in the Ethereum blockchain is presented here:

o Keys and addresses.

o Accounts.

o Transactions and messages.

o Ether cryptocurrency/tokens.

o The EVM.

o Smart contracts

Keys and Addresses

• Keys and addresses are used in Ethereum blockchain mainly to represent ownership and transfer of Ether.

• Keys are used in pairs of private and public type.

• The private key is generated randomly and is kept secret.

• Whereas a public key is derived from the private key.

• Addresses are derived from the public keys which are a 20-bytes code used to identify accounts.
Accounts

• Accounts are one of the main building blocks of the Ethereum blockchain.

• Two kinds of accounts exist in Ethereum:

o Externally Owned Accounts (EOAs).

o Contract Accounts (CAs).

Accounts vs UTXO Model

• Accounts Model (Ethereum): Tracks balances in accounts, like a bank. Supports smart contracts, intuitive, but
less private and state-heavy.

• UTXO Model (Bitcoin): Tracks unspent transaction outputs; balance is the sum of UTXOs. Like cash, you
combine coins to pay. Private, simple, but complex for smart contracts.

Transactions and Messages

• A transaction in Ethereum is a digitally signed data packet using a private key that contains the instructions
that, when completed, either result in a message call or contract creation.

• Transactions can be divided into two types based on the output they produce:

o Message Call Transactions:

▪ This transaction simply produces a message call that is used to pass messages from one
contract account to another.

o Contract Creation Transactions:

▪ As the name suggests, these transactions result in the creation of a new contract account. This
means that when this transaction is executed successfully, it creates an account with the
associated code

Transaction Structure

• Where a transaction is a tuple of the fields.

• Which is then included in a transaction trie (a modified Merkle-Patricia tree) composed of the transactions to
be included.

• The root node of transaction trie is included in the block header along with a list of transactions in the block.

Contract Creation Transaction

• A Contract Creation Transaction in Ethereum deploys a new smart contract to the blockchain, creating a
contract account with associated code.

Ether Cryptocurrency / Tokens (ETC and ETH)

• As an incentive to the miners, Ethereum also rewards its own native currency called Ether.

• After the DAO hack, a hard fork was proposed in order to mitigate the issue, therefore, there are now two
Ethereum blockchains:

o Ethereum Classic: Its currency is represented by ETC.

o Whereas the hard-forked version is ETH.


Ethereum Virtual Machine (EVM)

• EVM is a simple stack-based execution machine that runs bytecode instructions to transform the system state
from one state to another.

• The word size of the virtual machine is set to 256-bit.

• The stack size is limited to 1024 elements.

• EVM is a Turing-complete machine but is limited by the amount of gas that is required to run any instruction.

• This means that infinite loops that can result in denial-of-service attacks are not possible due to gas
requirements.

• EVM is an entirely isolated and sandboxed runtime environment.

• This results in increased security, deterministic execution, and allows untrusted code.

• There are two types of storage available to contracts and EVM:

o The first one is called memory, which is a byte array.

o When a contract finishes the code execution, the memory is cleared.

o It is akin to the concept of RAM.

o The other type is called storage which is permanently stored on the blockchain.

o It is a key-value store and can be thought of like a hard disk storage.


Ethereum DApp Development

Ethereum Decentralized Application or DApp

• DApp is an end-to-end application on a blockchain.

• DApp gives access to people, applications, and systems, not necessarily known to each other to transact peer
to peer.

• A DApp depends on the functionality of a blockchain for its infrastructure and operations.

• A DApp, or decentralized application, solves a problem that requires blockchain services and blockchain
infrastructure for realizing its purpose.

• Typically, a DApp has a web front-end, and a blockchain back end, and the code connecting the two.

DApps Stack

• A DApp stack includes layers that work together to make a decentralized app functional:

o Blockchain Layer: The Ethereum blockchain, handling data storage and smart contracts.

o Smart Contracts: Programs (written in Solidity) that run on the blockchain to manage logic and
transactions.

o Web3 Interface: Tools like [Link] to connect the front-end (web app) to the blockchain.

o Front-End: A user interface (e.g., HTML, JavaScript) for users to interact with the DApp.

o Storage (Optional): Decentralized storage like IPFS for files or data not stored on the blockchain.

DApp Architecture

• It allows us to build decentralized applications on the Ethereum blockchain.

• A typical DApp architecture includes:

o Front-End: A web or mobile interface for users (e.g., a website built with HTML/CSS/JavaScript).

o Back-End: Smart contracts on the Ethereum blockchain handling logic and data.

o Middleware: Code (like [Link]) that connects the front-end to the blockchain, enabling
communication.

DApp Three Tier Architecture

• DApps often follow a three-tier structure:

o Presentation Tier: The user interface (e.g., a web page) where users interact with the DApp.

o Logic Tier: Smart contracts on the Ethereum blockchain that process transactions and enforce rules.

o Data Tier: The blockchain itself, storing transaction data and smart contract states securely.

Truffle Framework

• It provides a suite of tools that allow us to write smart contracts with the Solidity programming language.

• It also enables us to test our smart contracts and deploy them to the blockchain.

• It also gives us a place to develop our client-side application.

• Install with: npm install -g truffle


Solidity Language

• Solidity is a programming language that is very close to JavaScript.

• Solidity is a statically-typed, case-sensitive, and object-oriented programming (OOP) language.

• Solidity code is written in Solidity files that have the extension .sol.

• A Solidity file is composed of the following four high-level constructs:

o Pragma

o Comments

o Import

o Contracts/library/interface

Pragma

• Pragma is generally the first line of code within any Solidity file.

• It is a directive that specifies the compiler version to be used for the current Solidity file.

• Solidity is a new language and is subject to continuous improvement on an ongoing basis.

• Whenever a new feature or improvement is introduced, it comes out with a new version.

• Example: pragma solidity ^0.8.0; (specifies to use Solidity version 0.8.0 or compatible).

Comments

• Any programming language provides the facility to comment code, and so does Solidity.

• There are the following three types of comments in Solidity:

o Single-line comments: Start with // and comment a single line. Example: // This is a comment.

o Multiline comments: Enclosed between /* and */ for multiple lines. Example: /* This is a multiline
comment */.

The Import Statement

• Keyword helps import other Solidity files, and we can access its code within the current Solidity file.

• The syntax for using import is as follows:

o import <<filename>>;

o Example: import '[Link]';

Contracts/Library/Interface

• We can define contracts, libraries, and interfaces at the global or top level.

• The library, contract, and interface keywords shown in the screenshot are case-sensitive in nature:

o Contract: A collection of functions and data (state variables) that resides on the Ethereum
blockchain. Example: contract MyContract { ... }.

o Library: Reusable code that can be called by contracts but doesn’t have its own state. Example:
library Math { ... }.

o Interface: Defines function signatures without implementation, used to interact with other contracts.
Example: interface IMyContract { ... }.
Structure of Smart Contract

• A contract consists of the following multiple constructs:

o State variables

o Structure definitions

o Modifier definitions

o Event declarations

o Enumeration definitions

o Function definitions

• Each of these constructs in turn consists of multiple other constructs.

State Variables

• Variables declared in a contract that are not within any function are called state variables.

• Each state variable has a type that must be defined statically.

• State variables also have additional qualifiers associated with them. They can be any one of the following:

o Private: Private variables (or functions) are only available to the current contract and not derived
contracts. Example: int private privateStateVariable;.

o Internal: Variables (or functions) that can only be accessed internally (current contract or derived).
Example: int internal StateVariable;.

o Public: This allows you to define variables (or functions) that can be called internally or through
messages. Example: int public publicStateVariable;.

o Constant: This qualifier makes state variables immutable. The value must be assigned to the variable
at declaration time itself. Example: bool constant hasIncome = true;.

Data Types

• Solidity provides the following multiple out-of-box data types:

o bool: This is a Boolean, which returns true or false. Example: bool isActive = true;.

o uint / int: Both int and uint represent integers, or number values. uint is unsigned (non-negative), int
can be negative. Example: uint256 count = 100; int256 balance = -50;.

o bytes: A dynamically-sized byte array. Example: bytes data = "hello";.

o string: A dynamically-sized string. Example: string name = "Alice";.

o address: The address type represents a 20-byte value, which is meant to store an Ethereum address.
Variables typed as address also have members, including balance and transfer. Example: address
owner = 0x123...;.

o mapping: Hash tables with key types and value types. Example: mapping(address => uint) balances;.

o struct: Structs allow you to define new types. Example: struct User { string name; uint age; }.

o enum: The enum keyword is used to declare enumerations. Example: enum Status { Active, Inactive }.
Functions

• Functions are the heart of Ethereum and Solidity.

• Functions are the mechanism to read and write values from/to state variables.

• Functions are a unit of code that can be executed on-demand by calling it.

• There are a couple of additional qualifiers that affect the behavior and execution of a function.

Function Qualifiers

• Public: Functions can be called by anyone, both within the contract and externally. Example: function
getValue() public returns (uint) { ... }.

• Internal: Functions can only be called within the contract or by derived contracts. Example: function
updateValue() internal { ... }.

• Private: Functions can only be called within the same contract, not by derived contracts. Example: function
secretFunction() private { ... }.

• External: Functions can only be called from outside the contract, not internally (except via this). Example:
function externalCall() external { ... }.

• View: Functions that do not modify the blockchain state, only read it. Example: function getBalance() view
returns (uint) { return balance; }.

• Pure: Functions that neither read nor modify the blockchain state, used for calculations. Example: function
add(uint a, uint b) pure returns (uint) { return a + b; }.

• Payable: Functions that can receive Ether when called. Example: function deposit() payable { ... }.

You might also like