8000 GitHub - andkob/EduChain: Implements a basic blockchain in Java. Designed to help understand the fundamental concepts of blockchain technology, including hashing, proof-of-work, and chain validation.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Implements a basic blockchain in Java. Designed to help understand the fundamental concepts of blockchain technology, including hashing, proof-of-work, and chain validation.

Notifications You must be signed in to change notification settings

andkob/EduChain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Blockchain in Java

This project implements a basic blockchain in Java. It is designed to help understand the fundamental concepts of blockchain technology, including hashing, proof-of-work, and chain validation.

Features

  • Block creation with timestamp, previous hash, data, and nonce
  • SHA-256 hashing for block security
  • Proof-of-work algorithm with adjustable difficulty
  • Blockchain validation to ensure data integrity
  • Serialization of the blockchain to JSON format for easy inspection

Prerequisites

  • Java Development Kit (JDK) 8 or higher

Installation

  1. Clone the repository:

    $ git clone https://github.com/andkob/EduChain.git
    $ cd EduChain

Compiling and Running

Manually

  1. Compile the project:

    $ javac -d bin -cp "./lib/*" src/*.java
  2. Run the project:

    $ java -cp "./bin;./lib/*" src.EduChain

Using Provided Shell Script

  1. Compile and run the project:

    $ ./run-demo.sh

Block Class

The Block class represents a single block in the blockchain. Each block contains the following properties:

Field Description
hash The current block's hash
prevHash The previous block's hash
data The block's data
timeStamp The time when the block was created
nonce The number used for mining

Block Methods

  • Block(String data, String prevHash): Constructor to initialize the block with data and previous hash.
  • String calculateHash(): Calculates the hash for the block.
  • void mineBlock(int difficulty): Mines the block by finding a hash that meets the difficulty criteria.

Utility Class

The Util class provides utility methods for the blockchain.

Util Methods

  • static String applySha256(String input): Applies the SHA-256 hash function to the input string and returns the resulting hash as a hexadecimal string.

Demo Class: EduChain.java

The EduChain class demonstrates a simple blockchain implementation in Java. It includes methods to validate the blockchain, add blocks, mine them with proof of work, and output the blockchain in JSON format.

The difficulty level for this demonstration can be changed by adjusting the value of the static variable difficulty. Example:

public static int difficulty = 4;

Acknowledgements

About

Implements a basic blockchain in Java. Designed to help understand the fundamental concepts of blockchain technology, including hashing, proof-of-work, and chain validation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0