This repository contains Project 1 (Mini-Blockchain) from the DecodeLabs Blockchain Technology internship program. It is built purely using Python 3 and standard library modules (hashlib, json, time, unittest).
index(int): Sequential block number.timestamp(float): Unix epoch creation timestamp.data(Any): Transaction payload string or object.previous_hash(str): 64-character SHA-256 hash of the preceding block ("0"for Genesis).nonce(int): Counter variable used in Proof of Work mining.hash(str): Deterministic SHA-256 string generated viacalculate_hash().
- Maintains an append-only block list (
self.chain). - Automatically initializes Block #0 (Genesis Block).
add_block(data): Mines and appends a new block linked to the latest block.is_chain_valid(): Cryptographically verifies stored hashes, chain pointers, and Proof of Work targets.
- Implements
mine_block(difficulty)wheredifficulty = 4. - Iteratively increments
nonceuntilhash.startswith("0" * difficulty).
Note for macOS users: Use
python3instead ofpythonin your terminal commands.
python3 main.pypython3 test_blockchain.pyor:
python3 -m unittest