Exploring the bitcoindevkit CLI part 1
Getting Started
There are a few ways to use bdk-cli
:
1. Building from source
By cloning the repo, building the library, and calling the resulting executable like so:
git clone https://github.com/bitcoindevkit/bdk-cli.git
cargo run -- wallet --descriptor "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)" sync
The first set of double dashes indicates to cargo that what follows are arguments to send to the executable.
You can keep using bdk-cli this way (with cargo run
), or you build from source and install the binaries so as to be able to use bdk-cli
directly (as in #2 below). To build/install, use
cargo install --path . --features repl,electrum,esplora
2. Installing the binary directly from crates.io
By installing the binaries directly from crates.io and calling the cli like so:
cargo install bdk-cli
bdk-cli wallet --descriptor "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)" sync
3. REPL
By entering the repl like this:
cargo install bdk-cli
bdk-cli repl --descriptor "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)"
The repl allows you to set the descriptor once and enter a read-eval-print-loop, where the cli tool will allow you to enter as many subcommands as you wish until you break out of the loop. It looks something like this:
bdk-cli repl --descriptor "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)"
>> sync
{}
>> list_transactions
[
{
"fees": 205,
"height": 1903506,
"received": 1580,
"sent": 0,
"timestamp": 1610371954,
"transaction": null,
"txid": "5a583f5f41eff6009a36bc0ad7fcbec494ac7f0719707dd4dd0f8fddbb3e0b26"
}
]
>> get_new_address
{
"address": "tb1q4er7kxx6sssz3q7qp7zsqsdx4erceahhax77d7"
}
Basic Workflow
The basic workflow of bdk-cli
looks like this:
- If you are using the cli, you provide a descriptor every time, followed by a subcommand
bdk-cli wallet --descriptor "wpkh(tprv8Z...fQtF/84'/1'/0'/0/*)" sync
bdk-cli wallet --descriptor "wpkh(tprv8Z...fQtF/84'/1'/0'/0/*)" list_transactions
bdk-cli wallet --descriptor "wpkh(tprv8Z...fQtF/84'/1'/0'/0/*)" get_new_address
- If you are using the repl, you provide a descriptor once (when entering the repl), and then as many subcommands as you want until you exit (but these subcommands can only apply to that one descriptor):
bdk-cli repl --descriptor "wpkh(tprv8Z...fQtF/84'/1'/0'/0/*)"
>> sync
>> list_transactions
>> get_new_address
Using the Manual Pages (help)
You can get information about how to use bdk-cli
by using
# cli
bdk-cli --help
# repl
>> help
You can also get additional information on specific commands and subcommands by adding them to the help
subcommand like so:
# cli
bdk-cli help list_transactions
bdk-cli help key generate
# repl
>> help list_transactions
or by using the --help
or -h
flag on any command and subcommand:
bdk-cli key --help
bdk-cli key restore --help
Map of Subcommands
The whole tree of subcommands for bdk-cli can be mapped like so:
bdk-cli ---| help
| repl
| key ------| help
| generate
| restore
| derive
| wallet ---| help
| broadcast
| bump_fee
| combine_psbt
| create_tx
| extract_psbt
| finalize_psbt
| get_balance
| get_new_address
| list_transactions
| list_unspent
| policies
| public_descriptor
| sign
| sync