Skip to content

mashuibr/educhain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

StudentChain - My Blockchain Learning Journey πŸš€

A hands-on learning project where I build a blockchain from scratch using Node.js, documenting every step of my journey.

πŸ“– About This Project

This is my personal learning project to understand blockchain technology for building decentralized applications (DApps). I'm creating a blockchain that stores student records as an example of how blockchain can be used beyond cryptocurrency - for decentralized data storage, verification systems, and transparent record-keeping.

🎯 Learning Objectives

  • Understand what a blockchain is and how it works
  • Learn about cryptographic hashing (SHA256)
  • Implement block creation and linking
  • Build chain validation mechanisms
  • Add proof of work (consensus mechanism)
  • Implement smart contracts/business logic - Coming Soon
  • Create a peer-to-peer network - Coming Soon
  • Build APIs for DApp interaction - Coming Soon

πŸ“š Learning Journey

βœ… Concept 1: Understanding Blocks

What I Learned:

  • A block is a container that holds data, timestamp, and links to previous blocks
  • Each block has a unique hash (like a fingerprint) calculated using SHA256
  • The hash depends on the block's content and the previous block's hash

What I Built:

  • Created the Block class with properties: index, timestamp, data, previousHash, hash
  • Implemented calculateHash() method using crypto-js library

Challenges:

  • Understanding how hashing works
  • Learning why the hash includes the previous block's hash

Code:

class Block {
    constructor(index, timestamp, data, previousHash = '') {
        this.index = index;
        this.timestamp = timestamp;
        this.data = data;
        this.previousHash = previousHash;
        this.hash = this.calculateHash();
    }
    
    calculateHash() {
        return SHA256(this.index + this.previousHash + this.timestamp + JSON.stringify(this.data)).toString();
    }
}

βœ… Concept 2: Building the Blockchain

What I Learned:

  • A blockchain is a linked list of blocks
  • The first block is called the "Genesis Block" and has no previous hash
  • Each new block must reference the previous block's hash
  • This creates an immutable chain - changing one block breaks the entire chain

What I Built:

  • Created the Blockchain class
  • Implemented createGenesisBlock() for the first block
  • Built addBlock() method to add new blocks
  • Added isValid() method to verify chain integrity

Challenges:

  • Understanding why we need a genesis block
  • Learning how to validate the entire chain

βœ… Concept 3: Chain Validation & Data Storage

What I Learned:

  • Blockchains can store any type of data (I chose student records)
  • JSON format works well for complex data structures
  • The chain validates itself by checking all block hashes
  • Validation ensures no blocks have been tampered with

What I Built:

  • Added student records as block data (USN, name, branch, semester)
  • Tested adding multiple blocks
  • Verified blockchain validation works

βœ… Concept 4: Proof of Work (Mining)

What I Learned:

  • Mining uses computational power to "prove" work was done before creating a block
  • Difficulty setting controls how hard it is to mine a block (number of leading zeros in hash)
  • Nonce is incremented until the hash meets the difficulty requirement
  • This prevents spam and secures the blockchain against tampering

What I Built:

  • Added nonce property to Block class
  • Implemented mineBlock(difficulty) method that finds valid hash
  • Set blockchain difficulty level (currently 10)
  • Tested mining with student records

Challenges:

  • Understanding why we need proof of work
  • Balancing difficulty (higher = more secure but slower)
  • Watching the mining process in action

Code:

mineBlock(difficulty) {
    while(this.hash.substring(0, difficulty) !== Array(difficulty + 1).join("0")) {
        this.nonce++;
        this.hash = this.calculateHash();
    }
    console.log("Block mined: " + this.hash);
}

πŸ› οΈ Current Implementation

Features Implemented βœ…

  • Block creation with SHA256 hashing
  • Genesis block initialization
  • Adding blocks to the chain
  • Chain validation (integrity checking)
  • Student data storage
  • Proof of Work (Mining) with adjustable difficulty
  • Nonce-based hash generation

Coming Next πŸ”œ

  • Proof of Stake consensus mechanism
  • Smart contract functionality
  • Transaction pools and mempool
  • Merkle trees for efficient verification
  • Peer-to-peer networking
  • REST API for DApp interaction
  • Data query and retrieval system
  • Access control and permissions
  • REST API for DApp interface
  • Peer-to-peer network

πŸ’» Installation & Usage

Prerequisites:

  • Node.js installed

Setup:

# Clone the repository
git clone https://github.com/mashuibr/educhain.git
cd educhain

# Install dependencies
npm install

# Run the blockchain
node main.js

πŸ“ Project Structure

educhain/
β”œβ”€β”€ main.js          # Complete blockchain implementation
β”œβ”€β”€ package.json     # Dependencies (crypto-js)
└── README.md        # This learning journal

πŸ”‘ Key Concepts Learned

1. Cryptographic Hashing

  • One-way function: easy to compute, impossible to reverse
  • Deterministic: same input always produces same output
  • Any change in input completely changes the hash

2. Chain Immutability

  • Each block contains the previous block's hash
  • Changing data in a block changes its hash
  • This breaks the link to the next block
  • Making the chain tamper-evident

3. Block Validation

  • Check if block's hash is correctly calculated
  • Verify the previous hash matches the actual previous block
  • Ensures chain integrity

πŸ“ Resources I'm Using

πŸ€” Questions I'm Exploring

  • How can blockchain be used for data verification without cryptocurrency?
  • What is proof of work and why is it needed for consensus?
  • How do multiple nodes reach consensus in a decentralized system?
  • How do DApps interact with the blockchain?
  • What makes blockchain better than traditional databases for certain use cases?

πŸ“Š Progress Tracker

  • Basic block structure
  • Blockchain class
  • Chain validation
  • Data storage (student records)
  • Proof of work implementation
  • Smart contract logic
  • Data access system
  • Network layer
  • API endpoints

πŸ’­ Reflections

What Surprised Me:

  • How simple the basic blockchain concept is
  • Why cryptographic hashing is so important
  • The elegant solution to creating immutable records

What's Challenging:

  • Understanding the mathematics behind hashing
  • Thinking about edge cases for validation
  • Planning the next steps (proof of work seems complex!)

πŸŽ“ Project Goals

This project is part of my journey to:

  1. Learn blockchain fundamentals through hands-on coding
  2. Understand decentralized applications (DApps) and how they work
  3. Explore blockchain use cases beyond cryptocurrency
  4. Build a foundation for creating decentralized systems
  5. Document my learning process for others

Note: This is a learning project and not meant for production use. I'm building this to understand how blockchain works, one concept at a time.

About

a decentralized student info storing system for convient retrieving of info of studnt in a uni or college

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages