Minimal Bitcoin wallet intended for teaching rust-bitcoin

Overview

Insanely minimal Bitcoin wallet intended for demonstration of Rust Bitcoin ecosystem

Absolutely DO NOT use with mainnet funds!!! No privacy - address reuse and other problems; no security review!

This code is intended for demonstration only. If you read it it should give you a better picture of rust-bitcoin and associated crates. Note that this is just basic introduction, not a comprehensive developer guide. It doesn't teach about security or other important practices - it'd require whole book, maybe even multiple books!

The code has regtest hard-coded. This would be normally a bad practice if this wasn't a demo.

Tutorial

The master branch contains only the skeleton which you can use to implement the wallet yourself. Implementing your own wallet will give you much better insight into Bitcoin and its Rust library. The skeleton provides configuration and database support.

Usage

Install and run bitcoind in regtest mode. Cryptoanarchy Debian Repository may help. If you install bitcoin-timechain-regtest you don't need any further configuration. Otherwise configure the wallet in ~/.config/pico-bitcoin-wallet/config.toml.

Create a wallet in bitcoind and mine some coins (mine at least 101 blocks so that coins are mature).

You should implement these commands:

  • address - returns the address of the wallet - create it from private key.
  • scan - scans the blocks to find matching transactions, should also tell the user how many coins were found.
  • send - creates a transaction that sends a given amount to the address provided in the input, bonus: implement BIP21

First version can be really very lazy if you like. E.g. require scan after sending transaction.

Tips and possible gotchas

Things that were discovered during implementation of solution that seem important to mention:

  • Note that the last block has number equal to block count, so the traditional last_height..current_height misses the last one.
  • Private key pair for Taproot needs to be tweked before signing - call .tap_tweak() on it and then convert it using to_inner.
  • To obtain a block from bitcoind you need to first get its hash using get_block_hash.
  • store_txos takes an iterator, don't bother with being clever if you are low on time - just collect to Vec and pass it in.
  • Don't bother with coin selection - just always spend all inputs, that'd be the best anyway if you actually reuse addresses.

Solution

There's a solution branch that contains fully working minimal example. You can use it if you decide to not write it yourself.

You might also like...
MyCitadel Wallet app for Linux, Windows & MacOS desktop made with GTK+
MyCitadel Wallet app for Linux, Windows & MacOS desktop made with GTK+

MyCitadel Desktop Bitcoin, Lightning and RGB wallet MyCitadel is a wallet for bitcoin, digital assets and bitcoin finance (#BiFi) smart contracts. It

MevWallet is a smart contract wallet that allows the user to capture MEV from Searchers, or create MEV on purpose.

MevWallet MevWallet is a smart contract wallet that allows the user to capture MEV from Searchers, or create MEV on purpose. This repo contains the so

Radix Babylon vanity address finder allowing easy import into Radix mobile Wallet.
Radix Babylon vanity address finder allowing easy import into Radix mobile Wallet.

Rad Vanity address finder for Radix Babylon which you can import directly into your Radix Wallet using QR scanner using Import from a Legacy Wallet fe

Automated Solana tool for quick arbitrage, customizable, with real-time data and wallet integration. Trade responsibly.
Automated Solana tool for quick arbitrage, customizable, with real-time data and wallet integration. Trade responsibly.

Solana Arbitrage Trading Tool The Solana Arbitrage Trading Tool is an automated solution crafted to spot and capitalize on arbitrage opportunities wit

🧩Creating a blockchain wallet and integrating a couple of cryptographic algorithms to securely save the secrets.🧩

Rust Library For Cryptocurrency Wallet Folder Structure src : contains the source code of the library examples : contains some examples of the library

A Rust library for working with Bitcoin SV

Rust-SV A library to build Bitcoin SV applications in Rust. Documentation Features P2P protocol messages (construction and serialization) Address enco

Rust command line program for Bitcoin brainwallet

brainwallet Rust command line program for Bitcoin brainwallet as implemented at https://www.bitaddress.org. To run it, first install Rust, e.g. from h

A bitcoin vanity address generator written with the Rust programming language.
A bitcoin vanity address generator written with the Rust programming language.

btc-vanity A bitcoin vanity address generator written with the Rust programming language. With btc-vanity you can create a private key which has a com

Flexible Rust implementation of the MuSig2 multisignature protocol, compatible with Bitcoin.

MuSig2 This crate provides a flexible rust implementation of MuSig2, an optimized digital signature aggregation protocol, on the secp256k1 elliptic cu

Comments
  • Attempt to improve the workshop

    Attempt to improve the workshop

    Some improvements (hopefully :)

    Patch 1 adds a dependency that reduces setup requiremens.

    Patch 2 does:

    • Improve the readme incl. workshop instructions
    • Add help command
    • Add docs to main.rs
    • Add lib.rs with constants
    • Add helper functions in lib.rs
    • Re-order code in lib.rs in an effort to improve the dev experience
    opened by tcharding 2
Owner
Martin Habovštiak
Beside programming, I'm interested in security, cryptography, Bitcoin and freedom. Attempt to hire me to shitcoin (non-Bitcoin coins) -> offending response
Martin Habovštiak
Modern, lightweight & standard-compliant bitcoin wallet runtime & cli without rust-bitcoin dependencies

Bitcoin protocol command-line wallet & tools Modern, minimalistic & standard-compliant cold wallet from LNP/BP Standards Association. Contributing Con

BP: Bitcoin protocol 3 Jul 31, 2023
Bitcoin Push Notification Service (BPNS) allows you to receive notifications of Bitcoin transactions of your non-custodial wallets on a provider of your choice, all while respecting your privacy

Bitcoin Push Notification Service (BPNS) Description Bitcoin Push Notification Service (BPNS) allows you to receive notifications of Bitcoin transacti

BPNS 1 May 2, 2022
⋰·⋰ Feeless is a Nano cryptocurrency node, wallet, tools, and Rust crate.

⋰·⋰ Feeless What is Feeless? Feeless is a Nano cryptocurrency node, wallet, tools, and Rust crate. This is not the official project for Nano, only an

null 127 Dec 5, 2022
Core Rust-C FFI for Stackmate Wallet.

STACKMATE-CORE A Rust-C FFI library exposing composite functionality from rust-bitcoin & bdk; to create cross-platform descriptor wallets. Currently u

Vishal Menon 5 May 31, 2022
A wallet library for Elements / Liquid written in Rust!

EDK Elements Dev Kit A modern, lightweight, descriptor-based wallet library for Elements / Liquid written in Rust! Inspired by BDK for Elements & Liqu

luca vaccaro 11 Dec 11, 2021
Open source Rust implementation of the Witnet decentralized oracle protocol, including full node and wallet backend 👁️🦀

witnet-rust is an open source implementation of the Witnet Decentralized Oracle Network protocol written in Rust. Components witnet-rust implements ma

The Witnet Project 155 Nov 21, 2022
Complete Ethereum and Celo wallet implementation and utilities in Rust

ethers.rs Complete Ethereum and Celo wallet implementation and utilities in Rust Documentation Extensive documentation and examples are available here

Georgios Konstantopoulos 1.5k Jan 8, 2023
HD wallet BIP-32 related key derivation utilities.

HDWallet Docs HD wallet(BIP-32) key derivation utilities. This crate is build upon secp256k1 crate, this crate only provides BIP-32 related features,

jjy 23 Nov 27, 2022
Vectis - Smart Contract Wallet

A smart contract wallet project to add functionality for users of DApps to manage their keys by allowing for recovery and account freeze, whilst preserving user control, and enabling relayer capability for gas provisioning

Nymlab 27 Dec 29, 2022
An open source desktop wallet for nano and banano with end-to-end encrypted, on chain messaging using the dagchat protocol.

An open source wallet with end-to-end encrypted, on chain messaging for nano and banano using the dagchat protocol.

derfarctor 22 Nov 6, 2022