Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Initial implementation of a CLI-based blockchain node
Description
This pull request introduces the initial version of
simple-btc-cli, a simplified, educational blockchain network built with TypeScript and Node.js. The project provides a hands-on demonstration of core blockchain concepts, including public/private key cryptography, proof-of-work, peer-to-peer communication, and transaction validation.The system is composed of three main components:
central-server.ts): A lightweight WebSocket server that acts as a message relay hub, allowing all miners to broadcast messages to each other.miner.ts): The core of the network. Each miner runs a node that maintains a copy of the blockchain, validates new transactions and blocks, performs proof-of-work (mining), and communicates with peers via the central server. It also exposes an HTTP API for wallet interactions.wallet-cli.ts): A command-line interface for users to interact with the blockchain. It allows users to create a wallet, check their balance, and send funds.This initial implementation establishes a fully functional, albeit simplified, blockchain ecosystem, providing a solid foundation for further exploration and feature development.
How to Set Up and Run
Prerequisites
1. Installation
First, clone the repository and install the required dependencies:
2. Build the Project
Compile the TypeScript source code into JavaScript for production use:
This command creates a
distdirectory containing the compiled code.3. Start the Network
The network requires at least two components to be running: the central server and one miner. Open three separate terminal windows in the project root.
Terminal 1: Start the Central Server
Terminal 2: Start a Miner Node
(To simulate a larger network, you can start additional miners in new terminals with
npm run start:miner -- <port> <reward_address>)4. Using the CLI Wallet
All wallet commands are executed via the
wallet:prodscript.Create a Wallet:
This generates a
wallet.jsonfile containing your public and private keys.Check Balance:
Send Coins:
The sender is implicitly the wallet defined in
wallet.json.Tell the Miner to Mine a Block:
This processes all pending transactions.