Skip to content

igmansvi/project-BlockChain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Basic Blockchain Implementation

A simple blockchain implementation in C++ that demonstrates the fundamental concepts of blockchain technology.

Overview

This project implements a basic blockchain with the following components:

  • Block structure with hash linking
  • Data storage capabilities
  • Blockchain management
  • File persistence (text and JSON formats)

Features

  • Block Structure: Each block contains index, timestamp, data, nonce, hash, and previous hash
  • Chain Management: Creating and managing a continuous chain of blocks
  • Hashing: SHA-256 hash function to secure block data
  • Persistence: Save blockchain to text and JSON files
  • Testing: Basic testing functionality

Flowchart

graph TD
    A[Start] --> B[Create Genesis Block]
    B --> C[Initialize Blockchain]
    C --> D{Add New Block?}
    D -->|Yes| E[Get Last Block]
    E --> F[Create New Block with Previous Hash]
    F --> G[Calculate Hash for New Block]
    G --> H[Add Block to Chain]
    H --> I[Save to File System]
    I --> D
    D -->|No| J[Display Blockchain]
    J --> K[End]

    subgraph "Block Structure"
    L[index] --> M[Block]
    N[timestamp] --> M
    O[data] --> M
    P[nonce] --> M
    Q[hash] --> M
    R[prevHash] --> M
    end

    subgraph "Hash Generation"
    S[Combine Block Data] --> T[Apply SHA-256]
    T --> U[Convert to Hex String]
    U --> V[Return 16-char Hash]
    end
Loading

Installation

Prerequisites

  • C++ compiler (g++ recommended)
  • OpenSSL library
  • nlohmann/json library

Build Instructions

# Navigate to project directory
cd d:\projectB

# Compile with OpenSSL and JSON include paths
g++ blockChain.cpp -o blockChain -IC:/OpenSSL-Win64/include -IC:/path/to/project/include -LC:/OpenSSL-Win64/lib -lssl -lcrypto

# Run the compiled program
.\blockChain

Usage

  1. Run the program
  2. Enter the number of blocks to create
  3. For each block, provide the data to store
  4. The program will display the blockchain after adding all blocks
  5. Blockchain data is saved to blockChain.txt and blockchain.json

Code Structure

  • info: Class to store data/transactions
  • block: Class representing a single unit in the blockchain
  • blockChain: Class for managing the chain of blocks
  • Utility functions for hashing, file I/O, and testing

Future Enhancements

  • Add validation, security mechanisms, and digital signatures
  • Implement Proof of Work (PoW) mining with nonce and difficulty level
  • Add error handling and testing features
  • P2P network implementation

Author

Mansvi Kumar

About

Basic BlockChain Implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages