This repository contains a toy implementation of the Bitcoin protocol based on the original whitepaper. It serves as a companion to the book “Building Bitcoin in Rust”.
“Building Bitcoin in Rust” is a comprehensive guide to understanding and implementing the core concepts of Bitcoin using the Rust programming language. You can find the book at:
https://braiins.com/books/building-bitcoin-in-rust
- Name: Lukáš Hozda
- Email: [email protected]
- X/Twitter: @LukasHozda (Preferred mode of communication)
If you have questions about the implementation, the book, or encounter issues with Rust, please use the GitHub Discussions feature in this repository.
To run this project, you’ll need to install Rust. We recommend using Rustup, the official Rust installer.
Open a terminal and run:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Follow the on-screen instructions to complete the installation.
- Download the Rustup installer from rustup.rs.
- Run the installer and follow the on-screen instructions.
After installation, restart your terminal or command prompt.
- Clone this repository:
git clone https://github.com/your-username/building-bitcoin-in-rust.git cd building-bitcoin-in-rust
- Compile the project:
cargo build --release
- Run the node:
cargo run --release --bin node -- [OPTIONS] [INITIAL_NODES...]
Options:
--port <PORT>
: Set the port number (default: 9000)--blockchain-file <FILE>
: Set the blockchain file location (default: “./blockchain.cbor”)
Example:
cargo run --release --bin node -- --port 9000 --blockchain-file ./my_blockchain.cbor 127.0.0.1:9001 127.0.0.1:9002
- Run the miner:
cargo run --release --bin miner -- --address <NODE_ADDRESS> --public-key-file <PUBLIC_KEY_FILE>
Example:
cargo run --release --bin miner -- --address 127.0.0.1:9000 --public-key-file miner_key.pub
- Run the wallet:
cargo run --release --bin wallet -- [OPTIONS]
Options:
-c, --config <FILE>
: Set the wallet config file (default: “wallet_config.toml”)-n, --node <ADDRESS>
: Set the node address
Example:
cargo run --release --bin wallet -- --config my_wallet_config.toml --node 127.0.0.1:9000
The source code in this repository is licensed under the ISC License:
Copyright (c) 2023, Lukáš Hozda Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Please note that this license applies only to the source code in this repository. The text of the book “Building Bitcoin in Rust” is proprietary and not covered by this license.