1.
Introduction to Blockchain
Blockchain is a decentralized, distributed ledger technology that records transactions across multiple
computers in a secure and transparent manner. It eliminates the need for intermediaries and ensures
data integrity through cryptographic hashing.
Key Characteristics:
Decentralized: No single point of control.
Immutable: Data cannot be altered once recorded.
Transparent: Transactions are visible to all participants.
Secure: Uses cryptographic techniques like hashing and digital signatures.
Consensus Mechanism: Ensures agreement among network participants.
2. Blockchain Data Structure
A blockchain consists of linked blocks, each containing:
Data: Transaction details.
Hash: Unique identifier for the block.
Previous Block Hash: Links blocks together.
Nonce: A number used in mining to generate a valid hash.
Each block is linked to the previous block, forming a chain, ensuring data integrity and security.
3. Features of Blockchain
1. Decentralization: Eliminates intermediaries.
2. Security: Uses cryptographic hashing (SHA-256).
3. Transparency: Transactions can be audited.
4. Immutability: Once recorded, data cannot be changed.
5. Efficiency: Reduces costs and time for transactions
4. Comparison: Blockchain vs Traditional Database
Feature Blockchain Traditional Database
Control Decentralized Centralized
Security High (cryptography) Vulnerable to attacks
Transparency Publicly verifiable Private access
Immutability Cannot be altered Can be modified
Intermediary No intermediaries Requires trusted third parties
5. Advantages of Blockchain Technology
Enhanced Security: Cryptographic encryption.
Decentralization: Eliminates the need for trusted authorities.
Transparency: Public ledgers ensure visibility.
Reduced Costs: No middlemen, fewer transaction fees.
Smart Contracts: Automate processes securely.
6. Hashing in Blockchain
Hashing converts input data into a fixed-length string, ensuring:
Data Integrity: Prevents tampering.
Uniqueness: Each input produces a unique hash.
Fast Verification: Hashes are easy to compare.
Algorithm Used: SHA-256 (Bitcoin uses this).
7. Consensus Algorithms
Ensure agreement among participants.
a) Proof of Work (PoW)
Used in Bitcoin.
Miners solve complex puzzles.
Energy-intensive but secure.
b) Proof of Burn (PoB)
Participants burn (destroy) a certain amount of cryptocurrency.
Gaining mining rights requires burning tokens.
c) Proof of Capacity (PoC)
Uses hard drive space instead of computational power.
More storage = higher chances of mining.
d) Proof of Stake Delegated (DPoS)
Participants stake coins to validate transactions.
Delegates are chosen based on reputation and stake.
e) Proof of Elapsed Time (PoET)
Uses a trusted execution environment (TEE).
Ensures fairness by selecting a random validator.
8. Types of Blockchain
1. Public Blockchain: Open to all (Bitcoin, Ethereum).
2. Private Blockchain: Restricted access (used in enterprises).
3. Hybrid Blockchain: Combination of public and private.
4. Consortium Blockchain: Controlled by a group (Hyperledger).
9. Ethereum Blockchain
A decentralized platform supporting smart contracts.
Uses Ether (ETH) as cryptocurrency.
Runs on Ethereum Virtual Machine (EVM).
10. Introduction to Solidity
Solidity is a high-level, statically-typed language used to write smart contracts on Ethereum. It is
influenced by JavaScript, Python, and C++.
11. Structure of Solidity
A basic Solidity contract contains:
Pragma Directive: Declares Solidity version.
Contract Definition: Defines contract logic.
State Variables: Stores contract data.
Functions: Contain contract operations.
Example:
pragma solidity ^0.8.0;
contract SimpleContract {
uint public number;
function setNumber(uint _num) public {
number = _num;
function getNumber() public view returns (uint) {
return number;
12. Solidity Variables
State Variables: Stored on blockchain.
Local Variables: Exist within functions.
Global Variables: Provide blockchain-related data.
13. Control Statements in Solidity
If-Else
Loops (For, While, Do-While)
Example:
function checkNumber(uint _num) public pure returns (string memory) {
if (_num > 10) {
return "Greater than 10";
} else {
return "Less than or equal to 10";
14. Structures in Solidity
Used for defining complex data types.
Example:
struct Student {
string name;
uint age;
15. Arrays in Solidity
Fixed Size Arrays
uint[] public numbers;
function addNumber(uint _num) public {
[Link](_num);
16. Functions in Solidity (Methods)
Public, Private, Internal, External
Pure & View functions
Payable functions
Example:
function getBalance() public view returns (uint) {
return address(this).balance;
17. Error Handling in Solidity
Used to prevent faulty transactions.
require(): Checks conditions before execution.
revert(): Stops execution and rolls back changes.
assert(): Used for debugging.
Example :s
function withdraw(uint _amount) public {
require(_amount <= balance, "Insufficient funds");
balance -= _amount;