khanya-blockchain
v1.0.0
Published
A lightweight blockchain library for Node.js that supports wallets, transactions, mining, and blockchain validation.
Maintainers
Readme
Khanya Blockchain
A lightweight blockchain library built in Node.js, supporting wallets, transactions, mining, and blockchain validation. Perfect for learning and experimenting with blockchain concepts.
Features
- Wallet creation with Elliptic Curve Cryptography (secp256k1)
- Transaction signing and validation
- Mining with proof-of-work
- Mining rewards
- Blockchain integrity verification
- Simple and modular architecture
- Easy to extend for advanced blockchain simulations
Installation
git clone https://github.com/KhanyadDlamini/khanya-blockchain.git
cd khanya-blockchain
npm install
# To install
npm install khanya-blockchainUsage
import { Blockchain } from './src/Blockchain.js';
import { Transaction } from './src/Transaction.js';
import { createWallet } from './src/Wallet.js';
// Create wallets
const alice = createWallet();
const bob = createWallet();
const miner = createWallet();
// Initialize blockchain
const khanyaCoin = new Blockchain();
// Create and sign transactions
const tx1 = new Transaction(alice.publicKey, bob.publicKey, 50);
tx1.signTransaction(alice.key);
khanyaCoin.addTransaction(tx1);
// Mine pending transactions
khanyaCoin.minePendingTransactions(miner.publicKey);
// Check balances
console.log('Alice:', khanyaCoin.getBalanceOfAddress(alice.publicKey));
console.log('Bob:', khanyaCoin.getBalanceOfAddress(bob.publicKey));
console.log('Miner:', khanyaCoin.getBalanceOfAddress(miner.publicKey));
// Validate blockchain
console.log('Blockchain valid?', khanyaCoin.isChainValid());
License
This project is licensed under the MIT License. See the LICENSE file for details
