Skip to content

first #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

first #24

wants to merge 1 commit into from

Conversation

nerdberg792
Copy link

@nerdberg792 nerdberg792 commented Jun 9, 2025

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:

  1. Central Server (central-server.ts): A lightweight WebSocket server that acts as a message relay hub, allowing all miners to broadcast messages to each other.
  2. Miner Node (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.
  3. CLI Wallet (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

  • Node.js (v18 or later)
  • npm

1. Installation

First, clone the repository and install the required dependencies:

git clone <repository-url>
cd simple-btc-cli
npm install

2. Build the Project

Compile the TypeScript source code into JavaScript for production use:

npm run build

This command creates a dist directory 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

    npm run start:central
  • Terminal 2: Start a Miner Node

    npm run start:miner

    (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

  • Terminal 3: Interact with the Wallet

All wallet commands are executed via the wallet:prod script.

  • Create a Wallet:

    npm run wallet -- create

    This generates a wallet.json file containing your public and private keys.

  • Check Balance:

    npm run wallet -- balance
  • Send Coins:
    The sender is implicitly the wallet defined in wallet.json.

    npm run wallet -- send <RECIPIENT_PUBLIC_KEY> <AMOUNT>
  • Tell the Miner to Mine a Block:
    This processes all pending transactions.

    npm run wallet -- mine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants