A Local Blockchain Network for Learning and Experimentation
BlockShare is a decentralized ledger and blockchain platform designed for running your own cryptocurrency in a local network environment. With a C++ core handling blockchain operations and a JavaScript-based API layer for client interactions, BlockShare provides a functional peer-to-peer network that supports transaction processing, balance management, and digital signature verification.
- 🌐 Local Cryptocurrency Network: Launch and manage a cryptocurrency network within a local WiFi environment.
- 🔄 Peer-to-Peer Node Communication: Supports decentralized networking for nodes to communicate, process transactions, and maintain data consistency.
- 🔒 Secure Transactions: Handles transaction signing and validation with digital signature verification.
- 🛠️ RESTful API for Client Interactions: Offers API endpoints for network participation, transaction submissions, and balance inquiries.
- 💰 Balance Management: Track individual account balances and total network balance.
⚠️ Note: BlockShare is intended for local network setups and educational purposes, not for deployment on public networks. It's a valuable resource for anyone wanting a hands-on approach to learning blockchain principles and creating a small-scale cryptocurrency.
- Node.js (v14 or higher)
- C++ Compiler (supporting C++11 or higher)
- npm or yarn package manager
- Machine with WinSock2 support for network operations
Step-by-step guide
- Clone the repository:
git clone https://github.com/Aradhya2708blockshare.git
cd blockshare
- Install Node.js dependencies:
npm install
- Compile C++ components:
# Compile main blockchain implementation
g++ blockchain.cpp -o blockchain -lws2_32
# Compile hash nonce utility
g++ hashNonce.cpp -o hashNonce
-
Create
.env
with IP and PORT -
Start the Node.js server:
npm run dev
- Execute the blockchain core:
./blockchain
- Add peer information in
/localdb/peers.json
Here’s how you can interact with your local BlockShare via REST API
Allow a new node to join the local network by specifying the desired port.
# say one of the nodes in the local network is running over 172.12.345.678:3000
curl -X POST http://172.12.345.678:3000/blockchain/contribute \
-H "Content-Type: application/json" \
-d '{
"provided_port": 8080,
}'
Submit a transaction, including details like sender, recipient, amount, nonce, and a signature.
curl -X POST http://172.12.345.678:3000/blockchain/submit-txn \
-H "Content-Type: application/json" \
-d '{
"sender": "sender_address",
"recipient": "recipient_address",
"amt": 100,
"nonce": 12345,
"sign": "transaction_signature"
}'
Retrieve the total balance across the network.
curl http://172.12.345.678:3000/blockchain/balance
Get the balance for a specific account address.
curl http://172.12.345.678:3000/blockchain/balance/0x123...abc
A typical balance response structure.
{
"account": "0x123...abc",
"balance": 1000
}
- Fork the repository to start working on your changes.
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request to merge your changes.