A complete blockchain implementation in Java featuring cryptocurrency transactions, digital wallets, and proof-of-work mining. This project demonstrates fundamental blockchain concepts including transaction validation, UTXO (Unspent Transaction Output) management, digital signatures, and Merkle trees.
- Blockchain Architecture: Complete blockchain with linked blocks and hash validation
- Cryptocurrency Transactions: Send and receive digital currency between wallets
- Digital Wallets: Secure wallet generation with ECDSA public/private key pairs
- Proof of Work Mining: Configurable difficulty mining with nonce calculation
- Transaction Validation: Digital signature verification and transaction integrity checks
- UTXO Management: Unspent Transaction Output tracking for accurate balance calculation
- Merkle Trees: Transaction hashing for block integrity
- Genesis Block: Initial block with pre-funded wallet for testing
Javachain/
βββ src/javachain/
β βββ javachain.java # Main class and blockchain logic
β βββ Block.java # Block structure and mining
β βββ Transaction.java # Transaction processing and validation
β βββ Wallet.java # Wallet management and key generation
β βββ TransactionInput.java # Transaction input handling
β βββ TransactionOutput.java# Transaction output management
β βββ StringUtil.java # Cryptographic utilities
βββ lib/
β βββ bcprov-jdk18on-1.81.jar # Bouncy Castle cryptography library
β βββ gson-2.6.2.jar # JSON serialization library
βββ README.md
οΏ½ README.md
-
Block Class:
- Contains transaction list, previous block hash, timestamp, and nonce
- Implements proof-of-work mining algorithm
- Calculates Merkle root for transaction verification
-
Transaction Class:
- ECDSA digital signature generation and verification
- Input/output value validation
- Transaction processing with UTXO management
-
Wallet Class:
- ECDSA key pair generation (prime192v1 curve)
- Balance calculation from UTXOs
- Transaction creation and signing
-
StringUtil Class:
- SHA-256 hashing utilities
- ECDSA signature operations
- Merkle tree root calculation
- Base64 encoding for key serialization
- ECDSA Cryptography: Elliptic Curve Digital Signature Algorithm for secure transactions
- SHA-256 Hashing: Cryptographic hashing for block and transaction integrity
- Bouncy Castle Provider: Industry-standard cryptographic library
- Transaction Validation: Multi-layer validation including signature verification and balance checks
- Java Development Kit (JDK) 8 or higher
- Command Line Interface (PowerShell, Command Prompt, or Terminal)
git clone https://github.com/ryukgod26/Javachain.git
cd JavachainThe project includes required JAR files in the lib/ directory:
bcprov-jdk18on-1.81.jar- Bouncy Castle Cryptography Providergson-2.6.2.jar- Google JSON library
javac -cp "lib/*" src/javachain/*.javajava -cp ".;lib/*" src.javachain.javachainFor Linux/Mac users, use colon separator:
java -cp ".:lib/*" src.javachain.javachainThe main class demonstrates:
- Creating wallets with cryptographic key pairs
- Genesis transaction with initial funding
- Mining blocks with proof-of-work
- Transaction processing between wallets
- Blockchain validation
Creating and Mining genesis Block...
Transaction Successfully added to the Block.
Block Mined ....000a1b2c3d4e5f6789abcdef...
The Balance of Wallet1 is: 100.0
Wallet1 is Sending 10 coins to Wallet2.
Transaction Successfully added to the Block.
Block Mined ....000f1e2d3c4b5a6978563412...
The Balance of Wallet1 is: 90.0
The Balance of Wallet2 is: 10.0
Blockchain is Valid.
The Blockchain is Correct and Working Perfectly.
erfectly.
Mining Difficulty: Adjust in javachain.java
public static int difficulty = 3; // Number of leading zeros requiredMinimum Transaction Value:
public static float minimumTransactionValue = 0.1f;The project includes comprehensive validation:
- Hash Integrity: Verifies block hash calculations
- Chain Validation: Ensures proper block linking
- Transaction Verification: Validates digital signatures
- UTXO Consistency: Checks input/output balance
- Mining Validation: Confirms proof-of-work compliance
- Blockchain Structure: Linked list of blocks with cryptographic hashes
- Mining Process: Proof-of-work algorithm finding hash with leading zeros
- Digital Signatures: ECDSA signing/verification for transaction authenticity
- UTXO Model: Bitcoin-style unspent transaction output tracking
- Merkle Trees: Efficient transaction verification structure
- Elliptic Curve: prime192v1 curve for key generation
- Hash Function: SHA-256 for all hashing operations
- Signature Algorithm: ECDSA with Bouncy Castle provider
- Encoding: Base64 for key serialization
- Modify transaction fees in
Transaction.java - Implement different mining algorithms in
Block.java - Add transaction types in the main blockchain logic
- Extend wallet functionality for multi-signature support
- Create multiple blockchain instances
- Implement consensus mechanisms
- Add peer-to-peer communication
This project demonstrates:
- Blockchain fundamentals and cryptocurrency mechanics
- Cryptographic implementations in Java
- Object-oriented design for complex systems
- Security considerations in distributed systems
- Data structures and algorithms in blockchain context
- Fork the repository
- Create a feature branch
- Implement your changes
- Add comprehensive tests
- Submit a pull request
This project is open source and available under the MIT License.
ryukgod26
- GitHub: @ryukgod26
Built with β€οΈ for learning blockchain technology