### BDK CLI Wallet Configuration Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/01-project-overview.md This TOML file demonstrates how to configure a wallet. Ensure the database type and client type match your setup. ```toml [ wallets.wallet_name] wallet = "wallet_name" network = "testnet4" ext_descriptor = "wpkh(...)" int_descriptor = "wpkh(...)" database_type = "sqlite" client_type = "electrum" server_url = "ssl://mempool.space:60002" batch_size = 10 ``` -------------------------------- ### Bitcoin Core RPC Configuration Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/05-wallet-configuration.md Configure a wallet to use the Bitcoin Core RPC client. This setup is for interacting directly with a running Bitcoin Core node via RPC, requiring authentication details. ```bash bdk-cli -n regtest wallet -w myrpc config \ -e "wpkh([path]xprv.../0/*)#checksum" \ -i "wpkh([path]xprv.../1/*)#checksum" \ -d sqlite \ -c rpc \ -u "127.0.0.1:18443" \ -a "user:password" ``` -------------------------------- ### Example: Setting up and Receiving a Payjoin Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/09-payjoin-operations.md This example demonstrates the complete workflow: creating a directory, initiating the receive_payjoin command with multiple OHTTP relays for redundancy, and the expected output format of the payjoin URI. ```bash # 1. Create directory for payjoin mkdir -p ~/payjoin_receiver # 2. Start receiving with two OHTTP relays for redundancy bdk-cli wallet -w receiver receive_payjoin \ --amount 100000 \ --directory ~/payjoin_receiver \ --ohttp_relay "https://pj.bobspacebkk.com" \ --ohttp_relay "https://pj.benalleng.com" \ --max_fee_rate 2 # 3. Returns payjoin URI (share with sender via QR code, email, etc.) # Output: bitcoin:tb1q...?amount=0.001&pj=https://relay.example.com?... ``` -------------------------------- ### Full Signature with Proof-of-Funds Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md Example of generating a full BIP322 signature with proof-of-funds, including specific UTXOs. ```bash bdk-cli wallet -w mywallets sign_message \ --message "I own these funds" \ --address "tb1q..." \ --signature_type fullproofoffunds \ --utxos "txid1:0" \ --utxos "txid2:1" ``` -------------------------------- ### Install bdk-cli from Source with Electrum Feature Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Installs a development version of bdk-cli from a local git repository, enabling the 'electrum' blockchain client feature. Verify the installation by running the help command. ```shell cd cargo install --path . --features electrum bdk-cli help # to verify it worked ``` -------------------------------- ### Install Build Tools Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Installs the necessary build tools, including gcc, required for building BDK from source. ```shell sudo apt-get install build-essential ``` -------------------------------- ### Payjoin Send Command Usage Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/09-payjoin-operations.md An example demonstrating how to use the `send_payjoin` command. It shows how to set the payjoin URI and OHTTP relay URLs, and notes that the transaction is automatically broadcast upon success. ```bash # 1. Receive payjoin URI from receiver (via QR, email, etc.) PAYJOIN_URI="bitcoin:tb1q...?amount=0.001&pj=https://relay.example.com?..." # 2. Send payjoin with matching relays bdk-cli wallet -w sender send_payjoin \ --uri "$PAYJOIN_URI" \ --fee_rate 5 \ --ohttp_relay "https://pj.bobspacebkk.com" \ --ohttp_relay "https://pj.benalleng.com" # 3. Transaction automatically broadcast if successful ``` -------------------------------- ### BDK-CLI JSON Response - Simple Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/11-integration-guide.md Provides a basic example of how to format a simple JSON response for a command. The result is serialized to a string. ```rust Ok(serde_json::json!({ "field": value, "nested": { "key": value } }).to_string()) ``` -------------------------------- ### Simple Message Signature Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md Example of generating a simple BIP322 signature for a message using the `sign_message` command. ```bash bdk-cli wallet -w mywallets sign_message \ --message "Hello, Bitcoin!" \ --address "tb1q..." ``` -------------------------------- ### Verify Message Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md Example of verifying a BIP322 signature using the `verify_message` command with the proof, message, and address. ```bash PROOF="..." # From sign_message output bdk-cli wallet -w mywallets verify_message \ --proof "$PROOF" \ --message "Hello, Bitcoin!" \ --address "tb1q..." ``` -------------------------------- ### Setup and Initial Wallet Sync Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/08-blockchain-synchronization.md This snippet shows how to generate keys, derive account keys, create wallet descriptors, configure a new wallet with SQLite and Electrum, and perform an initial full scan to discover transactions. ```bash # 1. Generate keys XPRV=$(bdk-cli key generate | jq -r '.xprv') # 2. Derive account keys ACCOUNT=$(bdk-cli key derive --xprv "$XPRV" --path "m/84'/1'/0'") XPUB=$(echo "$ACCOUNT" | jq -r '.xpub') # 3. Generate descriptor (add 0/* and 1/* for chains) EXT_DESC="wpkh([...path...]${XPUB}/0/*)#checksum" INT_DESC="wpkh([...path...]${XPUB}/1/*)#checksum" # 4. Configure wallet bdk-cli -n testnet4 wallet -w newtestnet config \ -e "$EXT_DESC" \ -i "$INT_DESC" \ -d sqlite \ -c electrum \ -u "ssl://mempool.space:60002" # 5. Full scan to discover transactions bdk-cli wallet -w newtestnet full_scan # 6. Check balance bdk-cli wallet -w newtestnet balance ``` -------------------------------- ### Setup a New BDK Wallet Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/README.md This snippet outlines the steps to set up a new wallet using the BDK CLI. It includes generating keys, configuring wallet settings with specific backends and descriptors, and syncing with the blockchain. ```bash # 1. Generate keys bdk-cli key generate ``` ```bash # 2. Configure wallet bdk-cli -n testnet4 wallet -w mywallets config \ -e "wpkh(xpub...)" \ -i "wpkh(xpub...)" \ -d sqlite \ -c electrum \ -u "ssl://mempool.space:60002" ``` ```bash # 3. Sync with blockchain bdk-cli wallet -w mywallets full_scan ``` -------------------------------- ### Esplora Configuration Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/05-wallet-configuration.md Configure a wallet to use the Esplora client, connecting to an Esplora-compatible server for blockchain indexing. This is suitable for services like mempool.space. ```bash bdk-cli -n testnet4 wallet -w myesplora config \ -e "wpkh([path]xpub.../0/*)#checksum" \ -i "wpkh([path]xpub.../1/*)#checksum" \ -d sqlite \ -c esplora \ -u "https://mempool.space/testnet/api" ``` -------------------------------- ### BDK CLI REPL Command Sequence Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md Demonstrates a typical command sequence within the BDK CLI REPL, including checking balance, generating a new address, viewing transactions, generating a key, and exiting the REPL. ```bash # Start REPL $ bdk-cli repl -w mywallets # Command sequence bdk-cli repl [mywallets]> balance { "total": 1000000, ... } bdk-cli repl [mywallets]> new_address { "address": "tb1q...", "index": 5 } bdk-cli repl [mywallets]> wallet transactions [ ... ] bdk-cli repl [mywallets]> key generate { "mnemonic": "...", ... } bdk-cli repl [mywallets]> exit $ ``` -------------------------------- ### Install bdk-cli from Crates.io with Electrum Feature Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Installs the latest tagged version of bdk-cli directly from crates.io, enabling the 'electrum' feature for online wallet commands. ```shell cargo install bdk-cli --features electrum ``` -------------------------------- ### Regular Sync and Transaction Workflow Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/08-blockchain-synchronization.md This example demonstrates a typical workflow: syncing the latest blockchain state, checking the balance, creating a new transaction, signing it locally, and broadcasting it to the network. ```bash # 1. Sync latest state bdk-cli wallet -w mywallets sync # 2. Check balance BALANCE=$(bdk-cli wallet -w mywallets balance | jq '.total') echo "Balance: $BALANCE satoshis" # 3. Create transaction PSBT=$(bdk-cli wallet -w mywallets create_tx \ --to "recipient:50000" \ --fee_rate 10 | jq -r '.psbt') # 4. Sign locally SIGNED=$(bdk-cli wallet -w mywallets sign "$PSBT" | jq -r '.psbt') # 5. Broadcast bdk-cli wallet -w mywallets broadcast --psbt "$SIGNED" ``` -------------------------------- ### Start BDK CLI REPL Mode Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md Initiates the interactive REPL mode for a specified wallet. This allows for repeated wallet operations without restarting the CLI process. ```bash bdk-cli repl --wallet mywallets ``` -------------------------------- ### Create and Broadcast Silent Payment Transaction Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md An example demonstrating how to generate a silent payment code, create a transaction to it, and then broadcast the transaction. ```bash # Generate silent payment code SP_CODE="sp1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq..." # Create transaction TX=$(bdk-cli wallet -w mywallets create_sp_tx \ --to-sp "$SP_CODE:100000" \ --fee_rate 5 | jq -r '.transaction') # Broadcast bdk-cli wallet -w mywallets broadcast --tx "$TX" ``` -------------------------------- ### BDK-CLI REPL Command Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/02-cli-commands.md Starts an interactive REPL shell session. Requires the wallet name to operate on. ```bash bdk-cli repl --wallet ``` -------------------------------- ### Configure Testnet Exploration Wallet Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/05-wallet-configuration.md Configure a wallet for exploring the testnet. This example specifies the network, descriptor, database type, client, URL, and block height. ```bash bdk-cli -n testnet4 wallet -w testnet_explore config \ -e "wpkh(tpub...)#checksum" \ -i "wpkh(tpub...)#checksum" \ -d sqlite \ -c electrum \ -u "ssl://mempool.space:60002" \ -b 20 ``` -------------------------------- ### Example TOML Wallet Configuration Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/02-cli-commands.md This TOML snippet shows the structure for configuring a BDK wallet, including network, descriptors, database, client, server, and batch size. ```toml wallets.my_wallet { wallet = "my_wallet" network = "testnet4" ext_descriptor = "wpkh([keypath]tpub.../0/*)#checksum" int_descriptor = "wpkh([keypath]tpub.../1/*)#checksum" database_type = "sqlite" client_type = "electrum" server_url = "ssl://mempool.space:60002" batch_size = 10 } ``` -------------------------------- ### Start Regtest Bitcoind Node Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Starts a regtest bitcoind node. Ensure your bitcoind is configured to run in regtest mode. ```shell just start ``` -------------------------------- ### Electrum Configuration Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/05-wallet-configuration.md Configure a wallet to use the Electrum client with a specified descriptor, database type, and server URL. This is useful for connecting to Electrum servers for blockchain data. ```bash bdk-cli -n testnet4 wallet -w myelectrum config \ -e "wpkh([59a5cd55/84'/1'/0']tpubDCEHVRzGPDP2Uq1bnKCJxDJmceS4qpw4PX4wU9VJz6REhKr2D4bduD6fKAdhwSEfHW3aqrN4cMMmHEX6w6zkK27Yw9JZUhphG8GnVGhV9w/0/*)#ukjxpqd7" \ -i "wpkh([59a5cd55/84'/1'/0']tpubDCEHVRzGPDP2Uq1bnKCJxDJmceS4qpw4PX4wU9VJz6REhKr2D4bduD6fKAdhwSEfHW3aqrN4cMMmHEX6w6zkK27Yw9JZUhphG8GnVGhV9w/1/*)#8wrwkxy2" \ -d sqlite \ -c electrum \ -u "ssl://mempool.space:60002" ``` -------------------------------- ### Get bdk-cli Usage Information Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Run this command to display the available options and commands for the bdk-cli binary. ```shell cargo run ``` -------------------------------- ### BDK CLI: Configure Wallet Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/INDEX.md Configure wallet settings, including name and descriptors. This command is used during new wallet setup. ```bash bdk-cli wallet -w name config ... ``` -------------------------------- ### Signer Error Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/04-error-handling.md Demonstrates a signer error when attempting to sign a PSBT without the necessary private key. ```bash bdk-cli wallet -w mywallet --ext-descriptor "wpkh(pub...)" sign # Error: Signer error: missing private key ``` -------------------------------- ### BDK-CLI Wallet Balance Command Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/README.md Example of how to check the balance of a wallet using the bdk-cli command-line interface. The output is shown in JSON format. ```bash # Command-line usage bdk-cli wallet -w mywallets balance # Output (JSON by default) { "total": 1000000, "confirmed": 500000, "unconfirmed": 500000, "immature": 0 } ``` -------------------------------- ### Example: BIP39 Error on Invalid Mnemonic Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/04-error-handling.md Demonstrates a BIP39 error triggered by providing an invalid mnemonic during key restoration. ```bash bdk-cli key restore --mnemonic "invalid words here" # Error: BIP39 error: invalid mnemonic ``` -------------------------------- ### Example: Create Transaction Error due to Insufficient Funds Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/04-error-handling.md Shows a 'CreateTx' error occurring when attempting to create a transaction with insufficient funds. ```bash bdk-cli wallet -w mywallet create_tx --to "addr:1000000" --fee_rate 100 # Error: Create transaction error: insufficient funds ``` -------------------------------- ### Electrum Client Error Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/04-error-handling.md Shows an error when the Electrum client fails to connect due to an invalid URL. ```bash bdk-cli -n testnet wallet -w mywallet --client-type electrum --url "invalid::url" full_scan # Error: Electrum error: invalid URL ``` -------------------------------- ### Example: Descriptor Error with Invalid Syntax Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/04-error-handling.md Illustrates a 'DescriptorError' resulting from providing a syntactically invalid descriptor. ```bash bdk-cli descriptor "invalid(descriptor)" # Error: Descriptor error: invalid descriptor ``` -------------------------------- ### Execute Balance Command Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/11-integration-guide.md Calculates and returns the wallet's total balance as a JSON string. This is an example of executing a specific wallet subcommand. ```rust match subcommand { WalletSubCommand::Balance => { let balance = wallet.balance(); Ok(json!({"total": balance.total(), ...}).to_string()) }, // ... other subcommands } ``` -------------------------------- ### BDK CLI: Derive Account Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/INDEX.md Derive an account from generated keys. This command is part of the new wallet setup process. ```bash bdk-cli key derive ... ``` -------------------------------- ### BDK CLI: Multisig Create Transaction Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/INDEX.md Create a transaction in a multisig setup. This is the initial step before signing by multiple parties. ```bash bdk-cli wallet -w signer1 create_tx ... ``` -------------------------------- ### Generate Fish Shell Completions Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md Installs fish shell completions for the BDK CLI. This involves creating a completions directory for fish and placing the generated script there, then sourcing the configuration. ```bash mkdir -p ~/.config/fish/completions bdk-cli completions fish > ~/.config/fish/completions/bdk-cli.fish source ~/.config/fish/config.fish ``` -------------------------------- ### Start Payjoin Session (Receiver) Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Initiates a Payjoin session as the receiver using regtest RPC. Requires the 'rpc' feature. Configure the wallet with an extended descriptor and specify OHTTP relays. ```shell cargo run --features rpc -- --network regtest wallet --wallet payjoin_wallet1 config --ext-descriptor "wpkh(tprv8ZgxMBicQKsPd2PoUEcGNDHPZmVWgtPYERAwMG6qHheX6LN4oaazp3qZU7mykiaAZga1ZB2SJJR6Mriyq8MocMs7QTe7toaabSwTWu5fRFz/84h/1h/0h/0/*)#8guqp7rn" --client-type rpc --database-type sqlite --url "127.0.0.1:18443" ``` ```shell cargo run --features rpc -- wallet --wallet payjoin_wallet1 sync ``` ```shell cargo run --features rpc -- wallet --wallet payjoin_wallet1 balance ``` ```shell cargo run --features rpc -- wallet --wallet payjoin_wallet1 receive_payjoin --amount 400000 --max_fee_rate 1000 --directory "https://payjo.in" --ohttp_relay "https://pj.bobspacebkk.com" --ohttp_relay "https://pj.benalleng.com" ``` -------------------------------- ### Get Wallet Balance (Pretty Output) Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/02-cli-commands.md Command to retrieve the balance of a wallet using the human-readable pretty ASCII table format. Requires the --pretty flag. ```bash bdk-cli --pretty wallet -w mywallet balance ``` -------------------------------- ### Send Bitcoin Transaction with BDK CLI Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/README.md This workflow demonstrates how to send a Bitcoin transaction using the BDK CLI. It covers syncing the wallet, creating a transaction, signing it, and broadcasting it to the network. Assumes `jq` is installed for PSBT parsing. ```bash # 1. Sync wallet bdk-cli wallet -w mywallets sync ``` ```bash # 2. Create transaction PSBT=$(bdk-cli wallet -w mywallets create_tx \ --to "recipient_addr:100000" \ --fee_rate 5 | jq -r '.psbt') ``` ```bash # 3. Sign SIGNED=$(bdk-cli wallet -w mywallets sign "$PSBT" | jq -r '.psbt') ``` ```bash # 4. Broadcast bdk-cli wallet -w mywallets broadcast --psbt "$SIGNED" ``` -------------------------------- ### Build the Project with Just Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Build the project using the 'build' recipe. ```shell just build ``` -------------------------------- ### Using Wallet Configuration from File Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/08-blockchain-synchronization.md Demonstrates how to use the BDK CLI to access wallet balance by referencing a pre-configured wallet in the config file. This avoids the need to repeatedly specify client details. ```bash # Stored in config file bdk-cli wallet -w mywallets balance # No need to provide: # - descriptor # - client_type # - server_url # - database_type ``` -------------------------------- ### Initiate Payjoin from Receiver Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/09-payjoin-operations.md The receiver starts a payjoin by specifying the amount, a directory for storing payjoin data, and one or more OHTTP relay endpoints. This command outputs a payjoin URI to be shared with the sender. ```bash PAYJOIN_URI=$(bdk-cli -n regtest wallet -w receiver receive_payjoin \ --amount 100000 \ --directory ~/payjoin_receiver \ --ohttp_relay "https://pj.bobspacebkk.com" \ --ohttp_relay "https://pj.benalleng.com" | jq -r '.payjoin_uri') echo "Share this URI with sender:" echo "$PAYJOIN_URI" ``` -------------------------------- ### Payjoin URL Parse Error Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/04-error-handling.md An example of a Payjoin URL parse error occurring when an invalid payjoin URI is provided. ```bash bdk-cli wallet -w mywallet send_payjoin --uri "invalid://uri" --fee_rate 10 --ohttp_relay "https://relay.example.com" # Error: Payjoin URL parse error ``` -------------------------------- ### Example: Base64 Decoding Error on Invalid PSBT Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/04-error-handling.md An example of a 'DecodeError' (specifically Base64 decoding) when signing with an invalid PSBT string. ```bash bdk-cli wallet -w mywallet sign "not-valid-base64!" # Error: Base64 decoding error: invalid padding ``` -------------------------------- ### Test the Project with Just Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Execute the project's tests using the 'test' recipe. ```shell just test ``` -------------------------------- ### Initialize BDK Wallet Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/11-integration-guide.md Creates a BDK Wallet instance, either by loading an existing configuration or creating a new one from provided command-line arguments. Requires wallet configuration and database path. ```rust // Load or create wallet let wallet = if let Some(wallet_opts_config) = wallet_config.get(&wallet_name)? { create_wallet(&wallet_opts_config, &cli_opts, &db_path)? } else { let wallet_opts = // ... from CLI args create_wallet(&wallet_opts, &cli_opts, &db_path)? } ``` -------------------------------- ### Inspect PSBT using psbt-utils Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/06-psbt-operations.md Decode and inspect the structure of a PSBT using the external `psbt-utils` tool. Ensure `psbt-utils` is installed via `cargo install psbt-utils` before use. The PSBT must be base64 decoded before piping to the inspect command. ```bash # Install psbt-utils (external tool) # cargo install psbt-utils # Inspect PSBT echo "cHNidP8BAJoCAAAAAljo..." | base64 -d | psbt-utils inspect ``` -------------------------------- ### Example: PSBT Extract Transaction Error Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/04-error-handling.md Demonstrates a 'PsbtExtractTxError' when attempting to extract a transaction from an incomplete PSBT. ```bash bdk-cli wallet -w mywallet extract_psbt # Error: PsbtExtractTxError: final_scriptwitness missing ``` -------------------------------- ### List Available Just Recipes Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Run this command to see all available recipes defined in the Justfile. ```shell just ``` -------------------------------- ### Generate Descriptor from Mnemonic Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/07-key-management.md Generates a descriptor directly from a mnemonic phrase. This simplifies the process when starting with a mnemonic. ```bash bdk-cli descriptor -t wpkh "word1 word2 ... word12" ``` -------------------------------- ### View BDK Configuration File Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/05-wallet-configuration.md Displays the current BDK configuration file located at ~/.bdk-bitcoin/config.toml. ```bash cat ~/.bdk-bitcoin/config.toml ``` -------------------------------- ### Configure Multiple Clients for Same Wallet Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/05-wallet-configuration.md Set up different client configurations for the same wallet. This involves creating separate wallet configurations for each client type. ```bash # Electrum version bdk-cli -n testnet4 wallet -w mywalletelectrum config \ -e "wpkh(xpub...)#checksum" \ -d sqlite -c electrum -u "ssl://mempool.space:60002" # Esplora version bdk-cli -n testnet4 wallet -w mywalletesplora config \ -e "wpkh(xpub...)#checksum" \ -d sqlite -c esplora -u "https://mempool.space/testnet/api" ``` -------------------------------- ### Get Public Wallet Descriptor Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/02-cli-commands.md Obtain the public version of the wallet descriptor(s), excluding any private key material. ```bash bdk-cli wallet -w public_descriptor ``` -------------------------------- ### Using Saved Configuration Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md After configuring settings, wallets can be loaded by name, utilizing parameters from the default configuration file (~/.bdk-bitcoin/config.toml). This allows for persistent settings across commands. ```bash # After config command, wallet loaded by name: bdk-cli wallet -w mywallets balance # All parameters from ~/.bdk-bitcoin/config.toml ``` -------------------------------- ### Get Wallet Balance Breakdown Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/02-cli-commands.md Fetch and display the total, trusted, untrusted, and immature balances for the wallet in satoshis. ```bash bdk-cli wallet -w balance ``` -------------------------------- ### Wallet Configuration Save and Load Methods Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/11-integration-guide.md Illustrates the methods for saving and loading wallet configurations to and from a TOML file. These methods are essential for persisting wallet settings between CLI sessions. ```rust impl WalletConfig { fn save(&self, datadir: &Path) -> Result<(), Error> } impl WalletConfig { fn load(datadir: &Path) -> Result, Error> } ``` -------------------------------- ### Get New Wallet Address Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/02-cli-commands.md Retrieve a new external address from the wallet. The output is in JSON or table format. ```bash bdk-cli wallet -w new_address ``` -------------------------------- ### Database Locked Error Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/04-error-handling.md Illustrates a database error where the database is locked, preventing operations like checking the balance. ```bash bdk-cli wallet -w mywallet balance # Error: Rusqlite error: database is locked ``` -------------------------------- ### Wallet Configuration to Runtime Options Conversion Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/11-integration-guide.md Shows the conversion process from a `WalletConfigInner` structure to `WalletOpts`, which are the runtime options used by the CLI. This is part of the configuration loading flow. ```rust impl TryFrom<&WalletConfigInner> for WalletOpts { fn try_from(config: &WalletConfigInner) -> Result } ``` -------------------------------- ### PSBT Creation with External and Internal Policies Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/06-psbt-operations.md Shows how to create a transaction using specific external and internal signing policies. This allows for fine-grained control over which policies are applied during transaction creation. ```bash # Create transaction using specific policies bdk-cli wallet -w mywallets create_tx \ --to "addr:100000" \ --external_policy "policy1" \ --internal_policy "policy2" ``` -------------------------------- ### Get Wallet Balance (JSON Output) Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/02-cli-commands.md Command to retrieve the balance of a wallet using the default JSON output format. ```bash bdk-cli wallet -w mywallet balance ``` -------------------------------- ### Configure Wallet Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/02-cli-commands.md Save wallet configuration to a TOML file. Use `--force` to overwrite existing configuration. ```bash bdk-cli wallet -w config [OPTIONS] -e [-i ] -d -c -u ``` -------------------------------- ### BDK CLI: Generate Keys Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/INDEX.md Generate cryptographic keys for your wallet. This is the first step in setting up a new wallet. ```bash bdk-cli key generate ``` -------------------------------- ### Configure Kyoto (Compact Filters) Client Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/08-blockchain-synchronization.md Configure BDK-CLI to use Kyoto (Compact Filters) for synchronization. Specify a dummy URL and the number of parallel peer connections. ```bash bdk-cli -n testnet4 wallet -w mywallets config \ -e "descriptor..." \ -d sqlite \ -c cbf \ -u "dummy://localhost" \ --cbf-conn-count 2 ``` -------------------------------- ### BDK-CLI Wallets List Command Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/02-cli-commands.md Lists all saved wallet configurations. Can output in a human-readable table format. ```bash bdk-cli wallets [--pretty] ``` -------------------------------- ### Configure BDK CLI with Environment Variables Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/11-integration-guide.md Commands can be configured using environment variables. This is useful for setting network and wallet names dynamically. ```rust #[arg(env = "NETWORK", ...)] pub network: Network, #[arg(env = "WALLET_NAME", ...)] pub wallet: String, ``` -------------------------------- ### Generate Descriptor using bdk-cli Key Commands Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/05-wallet-configuration.md Demonstrates generating a new private key (xprv) and deriving a key for descriptor creation using bdk-cli. ```bash bdk-cli key generate bdk-cli key derive --xprv --path "m/84'/1'/0'" ``` -------------------------------- ### Get Wallet Balance with Custom Logging Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Retrieves the wallet balance while enabling debug logging for bdk-cli, rusqlite, and rustls. This is useful for troubleshooting. ```shell RUST_LOG=debug,rusqlite=info,rustls=info cargo run --features electrum -- wallet --wallet sample_wallet balance ``` -------------------------------- ### Create or Load Regtest Bitcoind Wallet Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Use 'just create' to initialize a new wallet or 'just load' to access an existing one for the regtest bitcoind node. ```shell just create ``` ```shell just load ``` -------------------------------- ### Get First Unused Wallet Address Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/02-cli-commands.md Find and return the first unused external address from the wallet. Output is in JSON or table format. ```bash bdk-cli wallet -w unused_address ``` -------------------------------- ### Configure Airgapped Wallet (No Backend) Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/05-wallet-configuration.md Set up a wallet for airgapped operation without network access. Client type and URL are required but not used for offline commands. ```bash bdk-cli -n signet wallet -w airgapped config \ -e "wpkh([path]xpub.../0/*)#checksum" \ -i "wpkh([path]xpub.../1/*)#checksum" \ -d sqlite \ -c electrum \ -u "dummy://localhost" ``` -------------------------------- ### BDK-CLI Project Overview Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/DOCUMENTATION_COVERAGE.txt Provides an overview of the BDK-CLI project, its architecture, and general information. This is typically found in the main README file. ```markdown BDK-CLI TECHNICAL REFERENCE - DOCUMENTATION COVERAGE REPORT =========================================================== TASK: Analyze source code and generate precise technical reference as .md files STATUS: COMPLETED ✓ ANALYSIS SCOPE: - Source code repository: /workspace/home/bdk-cli (Bitcoin Dev Kit CLI v3.0.0) - Analysis depth: Complete public API surface - Documentation format: Markdown (.md) files DELIVERABLES CREATED: ==================== Total Files: 13 - 1 README (overview and navigation) - 1 INDEX (master reference table) - 11 Technical reference files File Breakdown: 01-project-overview.md (148 lines) - Project identity, architecture, overview 02-cli-commands.md (531 lines) - Complete command reference with all subcommands 03-types-and-structures.md (376 lines) - Data type definitions and structures 04-error-handling.md (311 lines) - Error catalog with all variants and conditions 05-wallet-configuration.md (372 lines) - Configuration system and persistence 06-psbt-operations.md (432 lines) - PSBT workflow and operations 07-key-management.md (380 lines) - Key generation and derivation (BIP39/BIP32) 08-blockchain-synchronization.md (482 lines) - Blockchain client operations 09-payjoin-operations.md (393 lines) - BIP 78 payjoin protocol implementation 10-advanced-features.md (515 lines) - Compiler, REPL, messaging, silent payments 11-integration-guide.md (550 lines) - Developer integration and architecture guide INDEX.md (397 lines) - Master index and quick reference tables README.md (262 lines) - Documentation overview and navigation Total Lines: 5,149 Total Size: 168 KB CONTENT COVERAGE: ================ ✓ Exported Functions/Methods: - 30+ CLI commands documented with full signatures - Parameter tables for all options - Return types with JSON examples - Usage examples for each command ✓ Type Definitions: - CliOpts - Global CLI options - CliSubCommand - Top-level command enum - WalletSubCommand - Wallet operations enum - OfflineWalletSubCommand - Offline operations (11 variants) - OnlineWalletSubCommand - Online operations (5 variants) - KeySubCommand - Key management (3 variants) - WalletConfig - Configuration container - WalletConfigInner - Wallet configuration - WalletOpts - Runtime wallet options - DatabaseType - Database backend enum - ClientType - Blockchain client enum - ProxyOpts - Proxy configuration - CompactFilterOpts - Compact filter options - Response types (Address, Balance, UTXO, PSBT, Transaction) ✓ Modules/Packages Documented: - commands.rs - CLI structure and definitions - handlers.rs - Command execution and business logic - config.rs - Configuration persistence - error.rs - Error types and conversions - utils.rs - Utility functions and wallet setup - persister.rs - Database abstraction - payjoin/mod.rs - Payjoin protocol orchestration - payjoin/ohttp.rs - OHTTP relay communication ✓ Error Catalog: - 30+ error variants documented - Trigger conditions for each error - Error recovery strategies - Automatic conversion implementations - Error handling patterns ✓ Configuration: - TOML file structure and location - Required and optional parameters - Client-specific options (Electrum, Esplora, RPC, Kyoto) - Configuration validation - Multiple examples for different networks - Best practices and security recommendations ✓ Endpoints/Commands: - 30+ wallet subcommands - 5+ key management commands - 5+ online wallet commands - 1 compile command (feature-gated) - 1 REPL command (feature-gated) - 2 payjoin commands - 2 message signing commands - 2 silent payment commands - 1 shell completion command - Additional utility commands ✓ Feature Flags: - electrum - Electrum blockchain client - esplora - Esplora REST API client - rpc - Bitcoin Core RPC client - cbf - Kyoto compact filter client - sqlite - SQLite database backend - redb - ReDB database backend - repl - Interactive REPL shell - compiler - Miniscript policy compiler - payjoin - BIP 78 payjoin protocol - bip322 - Message signing/verification - silent-payments - Silent payments support DOCUMENTATION QUALITY: ===================== ✓ Code Examples: - 100+ real usage examples - Command-line examples with actual flags - JSON response examples - Complete workflow examples - Multi-step integration patterns - Error recovery examples ✓ Tables and References: - Parameter tables for all commands - Type reference tables - Error variant tables - Network/client comparison tables - Feature flag overview tables - Quick reference tables ✓ Workflow Documentation: - 10+ complete workflow examples - Setup new wallet workflow - Send transaction workflow - Multisig signing workflow - Payjoin payment workflow - Air-gapped signing workflow - Key management workflow - Blockchain synchronization workflow ``` -------------------------------- ### Generate PowerShell Shell Completions Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md Installs PowerShell shell completions for the BDK CLI by appending the generated script to the user's PowerShell profile. ```powershell bdk-cli completions powershell >> $PROFILE ``` -------------------------------- ### BDK CLI: Full Wallet Scan Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/INDEX.md Perform a full scan of the blockchain to sync your wallet's transaction history. Used after initial setup. ```bash bdk-cli wallet -w name full_scan ``` -------------------------------- ### CLI Error Output Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/04-error-handling.md Shows how BDK CLI reports errors to the user, including a non-zero exit code and a formatted error message to stderr. ```bash $ bdk-cli wallet -w mywallet create_tx --to "invalid:100" Error: ParseError: invalid Bitcoin address format $ echo $? 1 ``` -------------------------------- ### Configure Wallet with Descriptors and Settings Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/07-key-management.md Configures a new wallet using the generated external and internal descriptors. This command also specifies the database type, blockchain pointer, and network. ```bash # Configure wallet with derived descriptors bdk-cli -n testnet4 wallet -w mywallets config \ -e "$EXT_DESC" \ -i "$INT_DESC" \ -d sqlite \ -c electrum \ -u "ssl://mempool.space:60002" ``` -------------------------------- ### Run bdk-cli with Electrum Client and Testnet Configuration Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Executes the bdk-cli binary with the 'electrum' feature enabled, configuring it for a testnet environment with specific wallet settings and a connection to a local Electrum server. ```shell RUST_LOG=debug cargo run --features electrum -- --network testnet4 wallet --wallet testnetwallet config --ext-descriptor "wpkh(tprv8ZgxMBicQKsPda2kR5xbHy1eVDWReS8CjQ9LaPL3UDubtA7ns1UcRbyaLMYy44YzBoBTgLCSKpMRXk1LcC5Wxm1r77QDsSJBqwejfftW3mY/84'/1'/0'/0/*)#t3xrg3ld" --client-type electrum --database-type sqlite --url "ssl://mempool.space:40002" ``` -------------------------------- ### Generate P2WSH Descriptor for Multisig Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/07-key-management.md Generates a P2WSH descriptor, often used as a template for multisignature setups. Ensure the correct extended public key is provided. ```bash bdk-cli descriptor -t wsh "xpub..." ``` -------------------------------- ### Generate Zsh Shell Completions Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md Installs zsh shell completions for the BDK CLI. This requires creating a directory for zsh functions and adding it to the fpath in the zshrc configuration. ```bash mkdir -p ~/.zfunc bdk-cli completions zsh > ~/.zfunc/_bdk-cli # Add to .zshrc: # fpath=(~/.zfunc $fpath) # autoload -Uz compinit && compinit source ~/.zshrc ``` -------------------------------- ### Backup BDK Configuration File Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/05-wallet-configuration.md Creates a backup copy of the current BDK configuration file. ```bash cp ~/.bdk-bitcoin/config.toml ~/.bdk-bitcoin/config.toml.backup ``` -------------------------------- ### Sync Wallet to Electrum Server Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/README.md Synchronizes a wallet using the Electrum client. Ensure the 'electrum' feature is enabled. The descriptor and URL are examples and should be replaced with your actual configuration. ```shell cargo run --features electrum -- --network testnet4 wallet --wallet sample_wallet config --ext-descriptor "wpkh(tprv8ZgxMBicQKsPda2kR5xbHy1eVDWReS8CjQ9LaPL3UDubtA7ns1UcRbyaLMYy44YzBoBTgLCSKpMRXk1LcC5Wxm1r77QDsSJBqwejfftW3mY/84'/1'/0'/0/*)#t3xrg3ld" --database-type sqlite --client-type electrum --url "ssl://mempool.space:40002" ``` ```shell cargo run --features electrum -- wallet --wallet sample_wallet full_scan ``` ```shell cargo run --features electrum -- wallet --wallet sample_wallet balance ``` -------------------------------- ### Compile Policy and Use in Wallet Config Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md Demonstrates compiling a Miniscript policy and then using the resulting descriptor to configure a new wallet. This involves capturing the descriptor output and passing it as an argument to the wallet configuration command. ```bash # 1. Compile policy DESC=$(bdk-cli compile "multi(2, A, B)" -t wsh | jq -r '.descriptor') # 2. Use in wallet config bdk-cli -n testnet4 wallet -w multisig config \ -e "$DESC" \ -d sqlite \ -c electrum \ -u "ssl://mempool.space:60002" ``` -------------------------------- ### Log Messages in Rust Code Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/11-integration-guide.md Provides examples of using the `log` crate macros to output debug, info, warning, and error messages within Rust code. ```rust use log::{debug, info, warn, error}; debug!("Syncing wallet: {}", wallet_name); info!("Wallet synced to height: {}", height); warn!("Low fee rate detected: {} sat/vB", fee_rate); error!("Failed to broadcast: {:?}", err); ``` -------------------------------- ### BDK-CLI Wallet Subcommand Structure Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/02-cli-commands.md Shows the structure for the wallet subcommand, requiring a wallet name and specific wallet options. ```bash bdk-cli wallet --wallet [WALLET_OPTIONS] ``` -------------------------------- ### BDK-CLI JSON Response - Array Example Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/11-integration-guide.md Shows how to serialize a vector of items into a pretty-printed JSON array string. This is used when a command needs to return a list of results. ```rust let items: Vec<_> = ...collect(); Ok(serde_json::to_string_pretty(&items)?) ``` -------------------------------- ### Verify Blockchain Connection Settings Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/04-error-handling.md If 'Blockchain Connection Fails', verify the server URL, network configuration, and firewall settings. This example shows connecting to an Electrum server. ```bash # Verify URL format and server status bdk-cli -n testnet wallet -w mywallet --client-type electrum --url "ssl://mempool.space:60002" sync ``` -------------------------------- ### Building BDK CLI with Cargo Features Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/11-integration-guide.md Shows how to build the BDK CLI using Cargo, specifying different feature flags to include or exclude functionality. Use `--features` to select specific features or `--all-features` to include everything. ```bash # Default features (repl + sqlite) cargo build ``` ```bash # Specific client cargo build --features electrum cargo build --features "electrum,esplora,rpc" ``` ```bash # All features cargo build --all-features ``` ```bash # Minimal (offline-only) cargo build --no-default-features --features sqlite ``` -------------------------------- ### Get Public Descriptor with BDK CLI Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/07-key-management.md Retrieves the public descriptor for a wallet. This command is useful for understanding the wallet's structure and for operations that only require public information. ```bash bdk-cli wallet -w mywallets public_descriptor # Get public descriptor ``` -------------------------------- ### Configure BDK CLI for Electrum Server Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/08-blockchain-synchronization.md Configure the BDK CLI to use an Electrum server for synchronization, which is generally faster than Esplora. Ensure the server URL is correct. ```bash bdk-cli -n testnet4 wallet -w mywallets config \ -f -c electrum -u "ssl://mempool.space:60002" ``` -------------------------------- ### BDK CLI Electrum Client Options Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/INDEX.md Configure the Electrum client with a batch size for requests. ```bash -b, --batch-size (default: 10) ``` -------------------------------- ### Generate Bash Shell Completions Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md Installs bash shell completions for the BDK CLI. This involves creating a directory and placing the generated completion script into it, followed by sourcing the script. ```bash mkdir -p ~/.local/share/bash-completion/completions bdk-cli completions bash > ~/.local/share/bash-completion/completions/bdk-cli source ~/.bashrc ``` -------------------------------- ### BDK CLI REPL Available Commands Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/10-advanced-features.md Lists the available commands within the BDK CLI's REPL mode. Commands like 'wallet', 'key', and 'descriptor' can be used without their usual prefixes. ```bash Commands: wallet - Wallet operations key - Key management descriptor [options] - Generate descriptors exit - Exit REPL ``` -------------------------------- ### Set Environment Variables for BDK CLI Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/11-integration-guide.md Demonstrates how to export environment variables to configure the BDK CLI for specific wallet and network settings. ```bash export WALLET_NAME=mywallets export NETWORK=testnet4 bdk-cli wallet -w $WALLET_NAME balance ``` -------------------------------- ### List Configured Wallets Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/05-wallet-configuration.md View all saved wallet configurations and their associated network and descriptor details. ```bash bdk-cli wallets ``` ```json { "wallets": { "wallet1": { "network": "testnet4", "descriptor": "wpkh(...)" }, "wallet2": { "network": "signet", "descriptor": "wpkh(...)" } } } ``` ```text Wallet Name Network Descriptor ───────────── ────────── ──────────────── wallet1 testnet4 wpkh(...)[truncated] wallet2 signet wpkh(...)[truncated] ``` -------------------------------- ### Implement Handler for New Subcommand Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/11-integration-guide.md Provides an example of implementing the handler function for a new subcommand in `handlers.rs`. This involves matching the subcommand variant and executing the corresponding logic, returning a JSON string. ```rust fn handle_offline_wallet_subcommand( wallet: &mut Wallet, wallet_opts: &WalletOpts, cli_opts: &CliOpts, subcommand: OfflineWalletSubCommand, ) -> Result { match subcommand { // ... existing matches OfflineWalletSubCommand::NewCommand { required_param, optional_param } => { // Implementation let result = wallet.some_operation(); Ok(serde_json::to_string_pretty(&json!({ "field": result }))?) } } } ``` -------------------------------- ### BDK CLI RPC Client Options Source: https://github.com/bitcoindevkit/bdk-cli/blob/master/_autodocs/INDEX.md Configure the RPC client using basic authentication or a cookie file. ```bash -a, --basic-auth (default: user:password) --cookie (cookie file path) ```