Skip to content

v-tanish012/Blockchain_Simulation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic Blockchain Implementation in C++

This is a simple blockchain implementation written in C++. It follows some principles from Bitcoin's design, including the use of SHA-256 for hashing, merkle trees, and a basic "mining" process.

Requirements

Command Line Interface (CLI)

The project includes a CLI that allows you to interact with the blockchain. You can view the longest chain of blockchain and add new blocks. By default, the CLI allows adding blocks up to 20 times before automatically quitting.

Peer-to-Peer Network

Instead of a full peer-to-peer network with WebSockets, this implementation uses HTTP requests to connect nodes to the network. Key aspects of the network include:

  • Tracking nodes in the network
  • Retrieving the latest chains from nodes to validate and stay up-to-date
  • Broadcasting your chain to the network when adding a new block

Conflict Resolution

In case of conflicting chains (e.g., different nodes have different versions of the blockchain), the longest chain is chosen. This implementation replaces the entire chain except for the genesis block when conflicts occur.

BlockChain Object

The BlockChain class manages the blockchain. Private variables include a vector of smart pointers to Block objects. It ensures the integrity of blocks by validating hashes and indices during block addition.

Mining (Proof of Work)

A simplified "mining" process is implemented using the findHash function to find a valid hash and nonce pair. The block's hash must start with "00" to be considered valid.

Block Object

The Block class represents individual blocks in the blockchain. Its properties are private for immutability, and methods exist to retrieve block information but not update it.

Steps to Run the Code

  1. Navigate to the directory where the main.cpp file resides.
  2. In the terminal, enter the following commands to compile the code:
    chmod +x compile.sh
    ./compile.sh
  3. Once the compilation is successful, run an instance of the node by entering:
    ./a.out
    

Contributors

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%