big renumber + writing of 04_2

This commit is contained in:
Shannon Appelcline 2026-03-26 15:30:03 -10:00
parent b48071342f
commit a2c2317328
No known key found for this signature in database
40 changed files with 534 additions and 113 deletions

View File

@ -265,7 +265,7 @@ You have a few options for what's next:
* Read the [StackScript](https://github.com/BlockchainCommons/Bitcoin-Standup-Scripts/blob/master/Scripts/LinodeStandUp.sh) to understand your setup.
* Read what the StackScript does in [Appendix I](A1_0_Understanding_Bitcoin_Standup.md).
* Choose an entirely alternate methodology for creating your VPS in [§2.2: Setting Up a Bitcoin-Core Machine via Other Means](02_2_Setting_Up_Bitcoin_Core_Other.md).
* Move on to "bitcoin-cli" with [Chapter Three: Understanding Your Bitcoin Setup](03_0_Understanding_Your_Bitcoin_Setup.md).
* Move on to "bitcoin-cli" with [Chapter Three: Preparing Your Bitcoin Wallet](03_0_Preparing_Your_Bitcoin_Wallet.md)
## Synopsis: Bitcoin Installation Types

View File

@ -16,4 +16,4 @@ Be sure that you are installing on a current version of your OS, to avoid proble
Unless you want to return to one of the other methodologies for creating a Bitcoin-Core node, you should:
* Move on to "bitcoin-cli" with [Chapter Three: Understanding Your Bitcoin Setup](03_0_Understanding_Your_Bitcoin_Setup.md).
* Move on to "bitcoin-cli" with [Chapter Three: Preparing Your Bitcoin Wallet](03_0_Preparing_Your_Bitcoin_Wallet.md)

View File

@ -1,4 +1,4 @@
# Chapter Three: Understanding Your Bitcoin Setup
# Chapter Three: Preparing Your Bitcoin Wallet
You're now ready to begin working with the `bitcoin-cli` command-line interface. But that first requires that you understand your Bitcoin setup and its wallet features, which is what will be explained in this chapter.
@ -11,24 +11,18 @@ After working through this chapter, a developer will be able to:
* Demonstrate that Their Bitcoin Node is Installed and Up-to-date
* Create Bitcoin Wallets
* Use Basic Wallet Commands
* Create an Address to Receive Bitcoin Funds
* Create an Address from a Descriptor
Supporting objectives include the ability to:
* Understand the Basic Bitcoin File Layout
* Use Basic Informational Commands
* Understand What a Bitcoin Address Is
* Understand What a Descriptor Wallet Is
* Recognize Common Types of Bitcoin Wallets
* Understand What a Ranged Descriptor Is
## Table of Contents
* [Section One: Verifying Your Bitcoin Setup](03_1_Verifying_Your_Bitcoin_Setup.md)
* [Section Two: Knowing Your Bitcoin Setup](03_2_Knowing_Your_Bitcoin_Setup.md)
* [Section Three: Setting Up Your Wallet](03_3_Setting_Up_Your_Wallet.md)
* [Section Four: Understanding the Descriptor](03_4_Understanding_the_Descriptor.md)
* [Section Five: Understanding the Address](03_5_Understanding_the_Address.md)
* [Section Six: Creating QR Codes for Addresses](03_6_Creating_QR_Codes_for_Addresses.md)
* [Section Seven: Receiving a Transaction](03_7_Receiving_a_Transaction.md)
* [Interlude: Using Command-Line Variables](03_7a_Interlude_Using_Command-Line_Variables.md)
* [Section Four: Understanding the Descriptor Wallet](03_4_Understanding_the_Descriptor_Wallet.md)

View File

@ -52,13 +52,13 @@ $ btcblock
295304/295304
```
> :link: **SIGNET vs MAINNET:** Remember that this tutorial generally assumes that you are using signet. If you're using the mainnet instead, you can retrieve the current block height with: `curl -s https://blockchain.info/q/getblockcount`. You can replace the latter half of the `btcblock` alias (between `/\$(` and `)'"`) with that.
> 🔗 **SIGNET vs MAINNET:** Remember that this tutorial generally assumes that you are using signet. If you're using the mainnet instead, you can retrieve the current block height with: `curl -s https://blockchain.info/q/getblockcount`. You can replace the latter half of the `btcblock` alias (between `/\$(` and `)'"`) with that.
If you're not up-to-date, but your `getblockcount` is increasing, no problem. Total download time can take from 15 minutes to several hours, depending on your setup.
## Optional: Know Your Server Types
> **SIGNET vs MAINNET:** When you set up your node, you choose to create it as either a Mainnet, Testnet, Signet, or Regtest node. Though this document presumes a Signet setup, it's worth understanding how you might access and use the other setup types — even all on the same machine! But, if you're a first-time user, skip on past this, as it's not necessary for a basic setup.
> 🔗 **SIGNET vs MAINNET:** When you set up your node, you choose to create it as either a Mainnet, Testnet, Signet, or Regtest node. Though this document presumes a Signet setup, it's worth understanding how you might access and use the other setup types — even all on the same machine! But, if you're a first-time user, skip on past this, as it's not necessary for a basic setup.
The type of setup is mainly controlled through the ~/.bitcoin/bitcoin.conf file.
If you're running signet, it probably contains this line:
@ -108,4 +108,4 @@ Before you start playing with bitcoin, you should make sure that your aliases ar
## What's Next?
Continue "Understanding Your Bitcoin Setup" with [§3.2: Knowing Your Bitcoin Setup](03_2_Knowing_Your_Bitcoin_Setup.md).
Continue "Preparing Your Bitcoin Wallet" with [§3.2: Knowing Your Bitcoin Setup](03_2_Knowing_Your_Bitcoin_Setup.md).

View File

@ -1,8 +1,9 @@
# 3.3: Setting Up Your Wallet
You're now ready to start working with Bitcoin. To begin with, you'll need to create a wallet for sending and receiving funds.
You're now ready to start working with Bitcoin. To begin with, you'll
need to create a wallet for sending and receiving funds.
> :warning: **VERSION WARNING:** Bitcoin Core is constantly
> ⚠️ **Version Warning:** Bitcoin Core is constantly
evolving. To reflect this, previous versions of this course offered
"VERSION WARNING"s for features that had been recently introduced. For
example, Bitcoin Core v0.21.0 (January 2021) stopped creating wallets
@ -87,46 +88,6 @@ $ bitcoin-cli getwalletinfo
You now have a Bitcoin wallet. But you can't receive funds with a wallet. For that you need an address, which is a specific repository for funds, derived from the private key information in your wallet: its one private key can generate many addresses.
## Create an Address
The next thing you need to do is create an address for receiving payments. This is done with the `bitcoin-cli getnewaddress` command. Remember that if you want more information on this command, you should type `bitcoin-cli help getnewaddress`. There are a variety of types of addresses, due to Bitcoin's evolution over the years. [§3.5](03_5_Understanding_the_Address.md) covers them all. For now, though we're just going to create an address of the default type, which is a Bech32 P2WPKH address.
```
$ bitcoin-cli getnewaddress
tb1q05ua6g7njnjrtsjc0t9w3jc6g2leeznasf4ny9
```
If you keep typing the command, you'll get a different address each time:
```
$ bitcoin-cli getnewaddress
tb1q0psqqqgy0fv5928wmk86ntu7hlax8dva7nl82p
$ bitcoin-cli getnewaddress
tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4
```
You can later look up the addresses you've generated with `bitcoin-cli getaddressesbylabel`, with the label being `""` unless you set one:
```
$ bitcoin-cli getaddressesbylabel ""
{
"tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4": {
"purpose": "receive"
},
"tb1q0psqqqgy0fv5928wmk86ntu7hlax8dva7nl82p": {
"purpose": "receive"
},
"tb1q05ua6g7njnjrtsjc0t9w3jc6g2leeznasf4ny9": {
"purpose": "receive"
}
}
```
Note that this address begins with an "tb1", which [means](https://en.bitcoin.it/wiki/List_of_address_prefixes) that it's a Bech32-encoded address on either signet or testnet. The discussion of different address types in [§3.5](03_5_Understanding_the_Address.md) will also talk about all of their identifying prefixes.
> :link: **SIGNET vs MAINNET vs TESTNET:** The equivalent mainnet address would start with a "bc1".
Take careful note of the address. You'll need to give it to whomever will be sending you funds.
> 📖 ***What is a Bitcoin address?*** A Bitcoin address is literally where you receive money. It's like an email address, but for funds. It's based on a public key, though different address schemes adjust that in different ways. Unlike an email address, a Bitcoin address should be considered single use: use it to receive funds just _once_. When you want to receive funds from someone else or at some other time, generate a new address. This is suggested in large part to improve your privacy. The whole blockchain is immutable, which means that explorers can look at long chains of transactions over time, making it possible to statistically determine who you and your contacts are, no matter how careful you are. If you keep reusing the same address, then this becomes even easier.
By creating your first Bitcoin address, you've also begun to fill in your Bitcoin wallet. More precisely, you've begun to fill the `wallet.dat` file in the appropriate `~/.bitcoin/signet /wallets/` directory. With a single address in hand, you could jump straight [§3.6: Receiving a Transaction](03_6_Receiving_a_Transaction.md) and begin receiving funds. However, before we get there, we're going to briefly discuss backing up your wallet and a few optional wallet commands that you might want to use in the future.
## Backup Your Wallet
You can backup your wallet with the `bitcoin-cli backupwallet` command:
@ -138,7 +99,7 @@ This will create a backup of the SQLite file that you can later restore from wit
Just having a single backup will usually be enough to recover your wallet, because it'll contain the seed used to generate the wallet (more on that next chapter). However, it's good to regularly backup your wallet so that you don't lose data about your transactions. (A few commands also force the creation of a new seed, and you'd need to backup your wallet again in those cases.)
## Optional: Encrypt Your Wallet
## Encrypt Your Wallet (Optional)
You can choose to encrypt your wallet. (It actually just encrypts the private information in your wallet, such as your private keys.) This is done with the `bitcoin-cli encryptwallet` command.
```
@ -158,7 +119,7 @@ If you want to lock your wallet back up earlier than that, you can use `bitcoin-
$ bitcoin-cli walletlock
```
## Optional: Reload Named Wallets
## Reload Named Wallets (Optional)
If you created a no-name (`""`) wallet, it will automatically load when you restart `bitcoind`. However, if you instead created a named wallet, it will not reload, forcing you to (initially) reload it by hand when you restart `bitcoind`.
```
@ -167,7 +128,8 @@ $ bitcoin-cli loadwallet mainwallet
"name": "mainwallet"
}
```
However, you can make a named wallet load on startup by adding a `true` to the end of the `bitcoin-cli loadwallet` command:
You can make a named wallet load automatically on future startups by adding a `true` to the end of the `bitcoin-cli loadwallet` command:
```
$ bitcoin-cli loadwallet mainwallet true
{
@ -176,7 +138,7 @@ $ bitcoin-cli loadwallet mainwallet true
```
Afterward, the wallet that you must recently flagged in this way should always be the one that appaers at startup.
## Optional: Create Multiple Wallets
## Create Multiple Wallets (Optional)
You can create multiple wallets if it's helpful for separating funds or separating different sorts of expenses:
```
@ -228,7 +190,12 @@ $ bitcoin-cli listwallets
```
As discussed above, named wallets will not load by default unless you use `loadwallet` with `true` as the second argument. In this example of `mainwallet` and `gamingfunds`, nothing would load when you restarted `bitcoind` unless you specified otherwise.
## Optional: Prove Control
In [§7.1](07_1_Creating_Multisig_Public_Keys.md), we'll create a
second wallet to provide watch-only access to multisigs. Be sure to
remember the `loadwallet` and `unloadwallet` commands, or else use
`-rpcwallet` so that you can properly access the right wallet.
## Prove Control (Optional)
In previous versions of Bitcoin Core, you were able to prove control of an address with the `bicoin-cli signmessage` command. This is generally a nice feature because it allows you to offer assurance to someone sending you funds that you'll definitely be able to retrieve those funds (or at least that you can currently). Because of the advent of descriptor wallets, which we'll talk about in the next section, this is no longer possible. You still _can_ prove control of an address by deriving a WIF-format private key from the descriptor for a particular address and then using `bitcoin-cli signmessagewithprivkey` with that specific key, but that's a complex process that goes beyond the scope of this course.
@ -240,4 +207,5 @@ You need to create an address to receive funds. That address is stored in a wall
## What's Next?
Continue "Understanding Your Bitcoin Setup" with [§3.4: Undestanding the Descriptor](03_4_Understanding_the_Descriptor.md) and then [§3.5: Understanding the Address](03_5_Understanding_the_Address.md).
Complete "Preparing Your Bitcoin Wallet" with [§3.4: Undestanding
the Descriptor Wallet](03_4_Understanding_the_Descriptor_Wallet.md).

View File

@ -0,0 +1,32 @@
# Chapter Four: Preparing Your Bitcoin Addresses
You set up your Bitcoin wallet in Chapter Three and considered its
ranged descriptors and how they could create (and recreate) thousands
of addresses. Those addresses are what you actually use to receive
funds on the Bitcoin network, and you'll be working with in this
chapter.
Besides creating addresses in a couple of different ways, you'll also
create means for easily transmitting your addresses to others and
(finally) _get some funds_, or at least some fake funds.
## Objectives for This Chapter
After working through this chapter, a developer will be able to:
* Create an Address to Receive Bitcoin Funds
* Create an Address from a Descriptor
* Create a QR from an Address
Supporting objectives include the ability to:
* Understand What a Bitcoin Address Is
* Understand an Address Descriptor
## Table of Contents
* [Section One: Understanding the Address](04_1_Understanding_the_Address.md)
* [Section Two: Integrating Addresses and Descriptors](04_2_Integrating_Addresses_Descriptors.md)
* [Section Three: Creating QR Codes for Addresses](04_3_Creating_QR_Codes_for_Addresses.md)
* [Section Four: Receiving a Transaction](04_4_Receiving_a_Transaction.md)
* [Interlude: Using Command-Line Variables](04_4a_Interlude_Using_Command-Line_Variables.md)

View File

@ -1,10 +1,20 @@
# 3.5: Understanding the Address
# 4.1: Understanding the Address
You understand your wallet now, but there's still the question of the addresses that it generates. Because, as it turns out, there are many sorts of addresses out there, some totally deprecated, some fairly bleeding edge, and some that are the default.
You understand your wallet now, but there's still the question of how
to turn its ranged descriptors into the addresses for receiving
funds. Because, there are a bunch of different address types: as you
saw, you have ranged descriptors to generate four types of addresses,
and it turns out, that's just the start.
## Understand Addresses
As you know, each Bitcoin address is a storage area for Bitcoin funds. Funds are sent from one address to another address as a _transaction_. But an address is more than just a storage area: it's a lockbox. The specifics of the address define how that lockbox is actually opened up. The default is to use a private key associated with the public key that was used to create the address, but that's not the only way that Bitcoin addresses work.
As you know, each Bitcoin address is a storage area for Bitcoin
funds. Funds are sent from one address to another address as a
_transaction_. But an address is more than just a storage area: it's a
lockbox. The specifics of the address define how that lockbox is
actually opened up. The default is to use a private key associated
with the public key that was used to create the address, but that's
not the only way that Bitcoin addresses work.
Different types of Bitcoin addresses change all of this. In general they may change:
@ -16,27 +26,56 @@ Different types of Bitcoin addresses change all of this. In general they may cha
### The Segwit Address(es)
All Bitcoin addresses have a "Pay-to" name. The default sort of address, which are Segwit addresses, are called P2WPKH, which stands for "Pay to Witness Public Key Hash." That's a mouthful that will make more sense when you've met the older address types. It's also called a Bech32 address (to describe its encoding method) or a SegWit address (to describe how its signature is stored), but there are other types of addresses that are also Bech32-encoded or SegWit.
All Bitcoin addresses have a "Pay-to" name. The default sort of
address, which are Segwit addresses, are called P2WPKH, which stands
for "Pay to Witness Public Key Hash." That's a mouthful that will make
more sense when you've met the older address types. It's also called a
Bech32 address (to describe its encoding method) or a SegWit address
(to describe how its signature is stored), but there are other types
of addresses that are also Bech32-encoded or SegWit.
SegWit came out of the Blocksize War of the '10s, where Bitcoin developers and users were trying to figure out a way to speed up the Bitcoin blockchain by allowing more transactions to be sent in less time. The result was the SegWit soft fork. It solved the problem by moving the signatures (which are the key that you use to unlock most Bitcoin transactions) from the middle of the transaction to the end, and then making that end space into increased space to store transactions that could be ignored by older servers. This allowed for a "blocksize increase" that was phased in gradually. The original version of SegWit used by P2WPKH is now called SegWit v0, with SegWit standing for "Segregated Witness", which describes that separation between the main part of the transaction and the signature.
SegWit came out of the Blocksize War of the '10s, where Bitcoin
developers and users were trying to figure out a way to speed up the
Bitcoin blockchain by allowing more transactions to be sent in less
time. The result was the SegWit soft fork. It solved the problem by
moving the signatures (which are the key that you use to unlock most
Bitcoin transactions) from the middle of the transaction to the end,
and then making that end space into increased space to store
transactions that could be ignored by older servers. This allowed for
a "blocksize increase" that was phased in gradually. The original
version of SegWit used by P2WPKH is now called SegWit v0, with SegWit
standing for "Segregated Witness", which describes that separation
between the main part of the transaction and the signature.
The specifics aren't that important. What is important is that P2WPKH, and a few other SegWit addresses that we'll meet shortly, are the default type of address; when you created an address in [§3.3](03_3_Setting_Up_Your_Wallet.md), you created a P2WPKH.
The specifics aren't that important. What is important is that P2WPKH,
and a few other SegWit addresses that we'll meet shortly, are the
default type of address; when you create address by default you'll be
creating a P2WPKH.
> 📖 **What is a fork?** A fork is a change to the Bitcoin protocol. This isn't a change to how one application (like Bitcoin Core) works, it's a change to how all of the members of the Bitcoin network agree to interact with each other. A hard fork makes new transactions incompatible with old transactions. It essentially creates two versions of Bitcoin (and most often has been used to actually create a new cryptocurrency). A soft fork ensures that old transactions remain compatible.
### The Rest of the Addresses
Here's a comprehensive listing of all the address types that have existed in Bitcoin's history, with the ❌ addreses largely deprecated (meaning don't worry about them!) and the ✅ addresses being the current ones (meaning that they will be relevant to your use of Bitcoin). Don't be overwhelmed by this list! If it looks like too much, just scan the ✅ addresses, which will be the only one used in this course, and come back and look at some of the other varieties if they come up and you want to figure out what they do exactly.
Here's a comprehensive listing of all the address types that have
existed in Bitcoin's history, with the ❌ addreses largely deprecated
(meaning don't worry about them!) and the ✅ addresses being the
current ones (meaning that they will be relevant to your use of
Bitcoin). Don't be overwhelmed by this list! If it looks like too
much, just scan the ✅ addresses, which will be the only one used in
this course, and come back and look at some of the other varieties if
they come up and you want to figure out what they do exactly.
The addresseses commonly in use for new Bitcoin addresses today are:
* **✅ P2WPKH (Pay to Witness Public Hash).** P2WPKH is a SegWit address that can be unlocked with a single key. This is the default address type for Bitcoin Core, and what you'll mostly be using. P2WPKH deprecates P2PKH.
* **✅ P2WSH (Pay to Witness Script Hash).** P2WSH is a SegWit address that can be unlocked by a script (rather than one or more private keys doing so). Scripts are described in [Chapter 11](11_0_Introducing_Bitcoin_Scripts.md) (and afterward). P2WSH deprecates P2SH.
* **✅ P2TR.** Taproot is the newest Bitcoin address type, but it was soft forked back in 2021, so it should have wide acceptance at this point. It's considered to be SegWit v1. Due to its use of Schnorr signatures, it can produce smaller transactions for multisigs, has privacy advantages, and can also combine singular signatures with scripts. It hasn't been widely adopted yet. We'll examing Taproot transcations starting in [Chapter 9](09_0_Expanding_Bitcoin_Transactions_with_Schnorr.md).
* **✅ P2TR.** Taproot is the newest Bitcoin address type, but it was soft forked back in 2021, so it should have wide acceptance at this point. It's considered to be SegWit v1. Due to its use of Schnorr signatures, it can produce smaller transactions for multisigs, has privacy advantages, and can also combine singular signatures with scripts. It hasn't been widely adopted yet. We'll examing Taproot transactions starting in [Chapter 9](09_0_Expanding_Bitcoin_Transactions_with_Schnorr.md).
Other addresses such as
[P2MR](https://github.com/bitcoin/bips/blob/master/bip-0360.mediawiki),
which proposes a quantum-resistant address, may appear in the future.
Other addresses such as [P2MR](https://github.com/bitcoin/bips/blob/master/bip-0360.mediawiki), which proposes a quantum-resistant address, may appear in the future.
The following two address types are not in wide use, but still hold large amounts of old funds:
The following two address types are not modern-day SegWit addresses, but they still hold large amounts of old funds:
* **❌ P2PKH (Pay to Public Key Hash).** The P2PKH address was the predominent address type prior to the introduction of SegWit, which replaced it with P2WKH. Most new addresses are now created with P2WPKH, since their transactions are cheaper, but many older P2PKH addresses still hold funds, since it was in use for roughly a decade.
* **❌ P2SH (Pay to Script Hash).** P2SH was the first type of scripting address, before signatures got revamped for SegWit, resulting in P2WSH.
@ -61,7 +100,14 @@ These last four address types are more totally deprecated:
## Understand Address Prefixes
Each different type of address is formed in a different way. An address can be derived in a different way, encoded in a different way, or formatted in a different way. As a result, addresses have different lengths and look different. Part of that formatting tends to be a prefix, which helps to identify an address type at a glance. The prefix is always different for mainnet and for the various testing networks (signet, testnet, regtest) so that you don't confuse fake funds and real funds.
Each different type of address is formed in a different way. An
address can be derived in a different way, encoded in a different way,
or formatted in a different way. As a result, addresses have different
lengths and look different. Part of that formatting tends to be a
prefix, which helps to identify an address type at a glance. The
prefix is always different for mainnet and for the various testing
networks (signet, testnet, regtest) so that you don't confuse fake
funds and real funds.
The following chart lists out the prefixes and encoding methods for each address type:
@ -75,16 +121,70 @@ The following chart lists out the prefixes and encoding methods for each address
| P2WSH | bc1q... | tb1q...| bech32 |
| P2TR | bc1p... | tb1p...| bech32m |
## Create More Addresses
## Create a P2WPKH Address
Though you'll stick with the default P2PWKH addresses most of the time, you may want to create other sorts of addresses. The `getnewaddress` RPC actually offers four types:
Now that you know what the types of addresses are, you're ready to
create one. This is done with the `bitcoin-cli getnewaddress`
command. With no arguments, it creates an address of the default
type, which is a Bech32 P2WPKH address.
```
$ bitcoin-cli getnewaddress
tb1q05ua6g7njnjrtsjc0t9w3jc6g2leeznasf4ny9
```
If you keep typing the command, you'll get a different address each time:
```
$ bitcoin-cli getnewaddress
tb1q0psqqqgy0fv5928wmk86ntu7hlax8dva7nl82p
$ bitcoin-cli getnewaddress
tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4
```
You can later look up the addresses you've generated with `bitcoin-cli getaddressesbylabel`, with the label being `""` unless you set one:
```
$ bitcoin-cli getaddressesbylabel ""
{
"tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4": {
"purpose": "receive"
},
"tb1q0psqqqgy0fv5928wmk86ntu7hlax8dva7nl82p": {
"purpose": "receive"
},
"tb1q05ua6g7njnjrtsjc0t9w3jc6g2leeznasf4ny9": {
"purpose": "receive"
}
}
```
Note that this address begins with an "tb1", which as noted above reveals that it's a
a Bech32-encoded address on either signet or testnet.
> 🔗 **SIGNET vs MAINNET vs TESTNET:** The equivalent mainnet address would start with a "bc1".
Take careful note of the address. You'll need to give it to whomever will be sending you funds.
> 📖 ***What is a Bitcoin address?*** A Bitcoin address is literally where you receive money. It's like an email address, but for funds. It's based on a public key, though different address schemes adjust that in different ways. Unlike an email address, a Bitcoin address should be considered single use: use it to receive funds just _once_. When you want to receive funds from someone else or at some other time, generate a new address. This is suggested in large part to improve your privacy. The whole blockchain is immutable, which means that explorers can look at long chains of transactions over time, making it possible to statistically determine who you and your contacts are, no matter how careful you are. If you keep reusing the same address, then this becomes even easier.
By creating your first Bitcoin address, you've also begun to fill in
your Bitcoin wallet. More precisely, you've begun to fill the
`wallet.dat` file in the appropriate `~/.bitcoin/signet /wallets/`
directory. With a single address in hand, you could jump straight
[§4.4: Receiving a Transaction](04_4_Receiving_a_Transaction.md) and
begin receiving funds. However, before we get there, we're going to
briefly discuss backing up your wallet and a few optional wallet
commands that you might want to use in the future.
## Create Other Address Types
Though you'll stick with the default P2PWKH addresses most of the
time, you may want to create other sorts of addresses. The
`getnewaddress` RPC actually offers four types:
| Flag | Type | Notes |
|------|------|-------|
| bech32 | P2PKH | Default |
| bech32 | P2PKH | default |
| bech32m | P2TR | |
| legacy | P2PK | Deprecated |
| p2sh-segwit | P2SH-PWPKH | Deprecated |
| legacy | P2PK | deprecated |
| p2sh-segwit | P2SH-PWPKH | deprecated |
Missing from this is P2WSH, but that's because it has its own methods for creation, as are described later in the book.
@ -104,18 +204,22 @@ $ bitcoin-cli getnewaddress "" p2sh-segwit
```
Note that the address prefixes match each of the expected types, with `p2sh-segwit` revealing itself as actually being a P2SH transaction.
It seems likely that the `legacy` and `p2sh-segwit` flags will be sunset some time in the future, as they were added to support the transition to SegWit that began in 2017.
It seems likely that the `legacy` and `p2sh-segwit` flags will be
sunset some time in the future, as they were added to support the
transition to SegWit that began in 2017.
## Summary: Understanding the Address
Addresses come in many types, and there have been several over the history of Bitcoin. However, you really only need to know about three:
Addresses come in many types, and there have been several over the
history of Bitcoin. However, you really only need to know about three:
* **P2WPKH.** Pay to Witness Public Key Hash. A SegWit v0 Bech32 address. This is the standard address for receiving funds, and what you'll use through most of this course.
* **P2WSH.** Pay to Witness Script Hash. A SegWit v0 Bech32 address. This is an address for receiving more complex transactions that can be spent by meeting the conditions of a script.
* **P2TR.** Pay to Tap Root. A Segwit v1 Bech32m address. Besides using Schnorr signatures, this is a sort of hybrid script that allows both single signing and the use of a Merkelized Alternative Script Tree.
It's easy to create most addresses with the `getnewaddress` command.
## What's Next?
Continue "Understanding Your Bitcoin Setup" with [§3.6: Creating QR Codes for Addresses](03_6_Creating_QR_Codes_for_Addresses.md).
Continue "Preparing Your Bitcoin Addresses" with
[§4.2 Integrating Addresses and Descriptors](04_2_Integrating_Addresses_Descriptors.md).

View File

@ -0,0 +1,318 @@
# 4.2: Integrating Addresses and Descriptors
You now have an understanding of your descriptor wallet and the
variety of addresses that it can create. You've even seen how your
descriptor wallet contains ranged descriptors for four sorts of
addresses.
But you can also have _non-ranged_ descriptors for individual
addresses. This section look at them.
## Examine an Address' Descriptor
You created a set of three addresses in the previous section. You can
see the details of any individual address with the `getaddressinfo`
command, including its individual descriptor:
```
$ bitcoin-cli getaddressinfo tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4
{
"address": "tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4",
"scriptPubKey": "00142a4f27c78470206e1a5948b47478d5b37991aac4",
"ismine": true,
"solvable": true,
"desc": "wpkh([e18dae20/84h/1h/0h/0/2]02040bf9b12e48bbbcbf72ef5197bc18067db378411ae6220f1d0a77da2ee7dbba)#dqt0983r",
"parent_desc": "wpkh([e18dae20/84h/1h/0h]tpubDC4ujMbsd9REzpGk3gnTjkrfJFw1NnvCpx6QBbLj3CHBzcLmVzssTVP8meRAM1WW4pZnK6SCCPGyzi9eMfzSXoeFMNprqtgxG71VRXTmetu/0/*)#3658f8sn",
"iswatchonly": false,
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "2a4f27c78470206e1a5948b47478d5b37991aac4",
"pubkey": "02040bf9b12e48bbbcbf72ef5197bc18067db378411ae6220f1d0a77da2ee7dbba",
"ischange": false,
"timestamp": 1770329126,
"hdkeypath": "m/84h/1h/0h/0/2",
"hdseedid": "0000000000000000000000000000000000000000",
"hdmasterfingerprint": "e18dae20",
"labels": [
""
]
}
```
This reveals the descriptor for this individual address:
```
"desc": "wpkh([e18dae20/84h/1h/0h/0/2]02040bf9b12e48bbbcbf72ef5197bc18067db378411ae6220f1d0a77da2ee7dbba)#dqt0983r",
```
You can compare that to the `parent_desc`, which contains the ranged
descriptor that this address descriptor is descended from (and that
you also saw when you listed out all of your descriptors):
```
"parent_desc": "wpkh([e18dae20/84h/1h/0h]tpubDC4ujMbsd9REzpGk3gnTjkrfJFw1NnvCpx6QBbLj3CHBzcLmVzssTVP8meRAM1WW4pZnK6SCCPGyzi9eMfzSXoeFMNprqtgxG71VRXTmetu/0/*)#3658f8sn",
```
They're in slightly different formats as the non-ranged address has
the derivation path all together rather than it being split in
two. But other than that, there are just two changes:
* The wallet descriptor has a range of addresses `0/*`, while the address descriptor displays one specific index in that range `0/2`.
* The checksums are different, as you'd expect due to the differences in the index number.
That's all that's different between a wallet descriptor and an address
descriptor (and that similarity is how the one is used to derive
hundreds or thousands of the other).
## Derive Addresses from a Descriptor
In fact, you can derive addresses from a descriptor on your own,
without having to use the `getnewaddress` command again and
again. This is done with the `deriveaddresses` command, which you give
a ranged descriptor, then tell it how far to derive to:
```
$ bitcoin-cli deriveaddresses "wpkh([e18dae20/84h/1h/0h]tpubDC4ujMbsd9REzpGk3gnTjkrfJFw1NnvCpx6QBbLj3CHBzcLmVzssTVP8meRAM1WW4pZnK6SCCPGyzi9eMfzSXoeFMNprqtgxG71VRXTmetu/0/*)#3658f8sn" 2
[
"tb1q05ua6g7njnjrtsjc0t9w3jc6g2leeznasf4ny9",
"tb1q0psqqqgy0fv5928wmk86ntu7hlax8dva7nl82p",
"tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4"
]
```
This example shows the derivation of addresses from the BIP-84 ranged
ndescriptor up through index "2". If you check this against the
addresses created in in the previous section, you'll see they're just
the same. Which is of course the whole point of descriptors! They are
deterministically derived in the same way every time.
The main purpose of this function would be to export addresses to
other services (for example, if you wanted to export watch-only
addresses to another wallet-app of if you wanted to watch a multisig
address, as we will in chapter 7).
> 📖 ***What is a watch-only address?*** A watch-only address allows
you to watch for transactions related to an address (or to a whole
family of addresses if you used a ranged descriptor), but not to spend
funds on those addresses.
## Create a Descriptor by Hand
Not only can you derive addresses from a descriptor by hand, but you
can also create a descriptor by hand.
There is an extensive list of descriptors that you can create on the
[Bitcoin Core
GitHub](https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md). Following
are a few examples.
Once you've created any descriptor, you can then import it with the
`importdescriptors` command that you used in
[§3.4](03_4_Understanding_the_Descriptor_Wallet.md).
Here's what it looked like to import a ranged desccriptor to become one of the `active` descriptors used to generate addresses in your wallet:
```
$ bitcoin-cli importdescriptors '[{ "desc": "wpkh(tprv8ZgxMBicQKsPd1dP4NpsFDpsLUCnZ7oyn4UEbYLw7if1EDVCxMgfSzAwP3aCr1YeRvX9GtGvHsCLdrM7zaDyh33jEj7joQoEeNEyJaSYm5p/84h/1h/0h/0/*)#grdqnase", "timestamp":1770329126, "active": true, "range": [0,10] }]'
```
You will change some of the variables when you import the new
descriptors you're creating below:
```
* **`active`** is not set if this is not a ranged descriptor meant to become one of defaults for creating new addresses.
* **`range`* is not set if it's a descriptor for a single address.
### Create a Watch-Only Wallet
Your default wallet (`""`) is set to hold private keys. You can use
that if you're importing descriptors where you have the private
key. However, if you want to import descriptors without private keys,
you need to create a special watchonly wallet:
```
$ bitcoin-cli createwallet "watchonly" true true
{
"name": "watchonly"
}
```
The two `true`s are the magic sauce as shown in the help file:
```
1. wallet_name (string, required) The name for the new wallet. If this is a path, the wallet will be created at the path location.
2. disable_private_keys (boolean, optional, default=false) Disable the possibility of private keys (only watchonlys are possible in this mode).
3. blank (boolean, optional, default=false) Create a blank wallet. A blank wallet has no keys.
```
The first `true` disables the use of private keys, the second `true` tells the wallet not to create keys of its own.
Remember that you're going to have to use `loadwallet` and
`unloadwallet` to cycle to right wallet, or else use a `-rpcwallet`
flag with every command to make sure you're using the wallet. (We'll
do the latter in the following examples.)
### Create an Address Descriptor
An address descriptor takes the form:
```
addr(ADDR)
```
Using this address descriptor would allow you to import one of the addresses you'd already
created into another wallet.
Creating a descriptor and importing it into Bitcoin Core is always a three-step process:
1. Create the descriptor.
```
addr(tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4)
```
2. Feed the descriptor into `getdescriptorinfo` to get a checksum.
```
$ bitcoin-cli getdescriptorinfo "addr(tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4)"
{
"descriptor": "addr(tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4)#4vmsvy3l",
"checksum": "4vmsvy3l",
"isrange": false,
"issolvable": false,
"hasprivatekeys": false
}
```
3. Import the descriptor with checksum.
```
$ bitcoin-cli -rpcwallet=watchonly importdescriptors '[{ "desc": "addr(tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4)#4vmsvy3l", "timestamp":1770329126 }]'
[
{
"success": true
}
]
```
Looking at the newly imported address reveals that the metadata is somewhat different from what was in the original wallet:
```
$ bitcoin-cli -rpcwallet=watchonly getaddressinfo tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4
{
"address": "tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4",
"scriptPubKey": "00142a4f27c78470206e1a5948b47478d5b37991aac4",
"ismine": true,
"solvable": false,
"parent_desc": "addr(tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4)#4vmsvy3l",
"iswatchonly": false,
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "2a4f27c78470206e1a5948b47478d5b37991aac4",
"ischange": false,
"labels": [
""
]
}
```
For example, we no longer have the ranged `parent_desc` and this one
is not `solvable` (we don't have the private key!). Nonetheless it's
the same address, which means that it's unlocked in the same way (as
shown by the identical `scriptPubKey`, a topic we'll return to).
### Create a Keyed Descriptor
The `pk`, `pkh`, and `wpkh` descriptors are all equally easy to
create, since they just the form of `function(key)`.
If we go back to our original `getaddressinfo`, we can find that the
public key for the address
`tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4` is:
```
"pubkey": "02040bf9b12e48bbbcbf72ef5197bc18067db378411ae6220f1d0a77da2ee7dbba",
```
That means the wpkh descriptor would be:
```
wpkh(02040bf9b12e48bbbcbf72ef5197bc18067db378411ae6220f1d0a77da2ee7dbba)
```
We retrieve a checksum for it:
```
$ bitcoin-cli getdescriptorinfo "wpkh(02040bf9b12e48bbbcbf72ef5197bc18067db378411ae6220f1d0a77da2ee7dbba)"
{
"descriptor": "wpkh(02040bf9b12e48bbbcbf72ef5197bc18067db378411ae6220f1d0a77da2ee7dbba)#3303qrm5",
"checksum": "3303qrm5",
"isrange": false,
"issolvable": true,
"hasprivatekeys": false
}
```
Then we import it:
```
bitcoin-cli -rpcwallet=watchonly importdescriptors '[{ "desc": "wpkh(02040bf9b12e48bbbcbf72ef5197bc18067db378411ae6220f1d0a77da2ee7dbba)#3303qrm5", "timestamp":1770329126 }]'
[
{
"success": true
}
]
```
Voila, we have round-tripped the address via a descriptor with the public key:
```
$ bitcoin-cli -rpcwallet=watchonly getaddressesbylabel ""
{
"tb1q9f8j03uywqsxuxjefz68g7x4kduer2ky6shsf4": {
"purpose": "receive"
}
}
```
> 📖 **Why didn't we supply a derivation path?** Derivation paths
derive child keys from master keys. If we wanted to create a ranged
descriptor we'd need a derivation path so that all the indexed keys
could be created. Similarly, if we knew the master key but not the
address key, we'd need a derivation path. In this case, we had the
specific key for this specific address, and so no derivation path was
needed.
## Create Other Descriptors
This process could be repeated in a number of different ways. You
could create a descriptor with a private key instead of a public key,
and import it into non-watchonly wallet. You could create a ranged
descriptor by hand and import a whole set of addresses. Although it's
not best practice, you could even use the same key to create different
types of addresses. (Try it out: just replace the "wpkh" above with
"pkh", get a new checksum, and import and you'll have a P2PKH address
instead of a P2WPKH address, unlocked by the same key.)
The main purpose here is to show how descriptors work in practice, so
that the link between descriptors and address is clear, and so you can
easily create addresses from descriptors when it's helpful in the
future, such as when we create multisigs.
## Summary: Integrating Addresses and Descriptors
In the modern Bitcoin ecosystem, addresses and descriptors go hand in
hand—and it's not just that you use ranged descriptors to create sets
of address.
* You can view descriptors from individual addresses.
* You can derive addresses directly from descriptors.
* You can generate descriptors by hand and turn them into addresses.
These are powerful techniques that we may not use a lot on the command
line, but which are crucial to an overall understand of how Bitcoin
works.
## What's Next?
Continue "Preparing Your Bitcoin Addresses" with [§4.3: Creating QR
Codes for Address](04_3_Creating_QR_Codes_for_Addresses.md).

View File

@ -1,4 +1,4 @@
# 3.6: Creating QR Codes for Addresses
# 4.3: Creating QR Codes for Addresses
To date we've been displaying addresses as little bits of bech32- and base58-encoded data. That's great if you can cut and paste them or if you can store them in shell variables. But what if you're trying to transmit an address between devices that aren't on the same network, or that don't have a direct connection even if they are? That's where QR Codes come into play.
@ -89,7 +89,7 @@ You won't be creating more QR Codes in this course (except when we briefly touch
## What's Next?
Conclude "Understanding Your Bitcoin Setup" with [§3.7: Receiving a Transaction](03_7_Receiving_a_Transaction.md).
Conclude "Preparing Your Bitcoin Addresses" with [§4.4: Receiving a Transaction](04_4_Receiving_a_Transaction.md).

View File

@ -1,4 +1,4 @@
# 3.7: Receiving a Transaction
# 4.4: Receiving a Transaction
You're now ready to receive some money at an address you created.
@ -363,9 +363,9 @@ Faucets will give you money on the testnet. They come in as raw transactions, wh
## What's Next?
For an aside on using command-line variables that will be vital to the rest of this course, read [Interlude: Using Command-Line Variables](03_7a_Interlude_Using_Command-Line_Variables.md).
For an aside on using command-line variables that will be vital to the rest of this course, read [Interlude: Using Command-Line Variables](04_4a_Interlude_Using_Command-Line_Variables.md).
If you're already comfortable with them, continue on to [Chapter Four: Sending Bitcoin Transactions](04_0_Sending_Bitcoin_Transactions.md).
If you're already comfortable with them, continue on to [Chapter Five: Sending Bitcoin Transactions](05_0_Sending_Bitcoin_Transactions.md).

View File

@ -34,35 +34,40 @@ If you'd like to make your own translation, please see [Contributing](https://gi
### PART TWO: SENDING TRANSACTIONS
* [3.0: Understanding Your Bitcoin Setup](03_0_Understanding_Your_Bitcoin_Setup.md)
* [3.0: Preparing Your Bitcoin Wallet](03_0_Preparing_Your_Bitcoin_Wallet.md)
* [3.1: Verifying Your Bitcoin Setup](03_1_Verifying_Your_Bitcoin_Setup.md)
* [3.2: Knowing Your Bitcoin Setup](03_2_Knowing_Your_Bitcoin_Setup.md)
* [3.3: Setting Up Your Wallet](03_3_Setting_Up_Your_Wallet.md)
* [3.4: Understanding the Descriptor](03_4_Understanding_the_Descriptor.md)
* [3.5: Understanding the Address](03_5_Understanding_the_Address.md)
* [3.6: Creating QR Codes for Addresses](03_6_Creating_QR_Codes_for_Addresses.md)
* [3.7: Receiving a Transaction](03_7_Receiving_a_Transaction.md)
* [Interlude: Using Command-Line Variables](03_7a_Interlude_Using_Command-Line_Variables.md)
* [4.0: Sending Bitcoin Transactions](04_0_Sending_Bitcoin_Transactions.md)
* [4.1: Sending Coins the Easy Way](04_1_Sending_Coins_The_Easy_Way.md)
* [4.2: Creating a Raw Transaction](04_2_Creating_a_Raw_Transaction.md)
* [Interlude: Using JQ](04_2a_Interlude_Using_JQ.md)
* [4.3: Creating a Raw Transaction with Named Arguments](04_3_Creating_a_Raw_Transaction_with_Named_Arguments.md)
* [4.4: Sending Coins with Raw Transactions](04_4_Sending_Coins_with_a_Raw_Transaction.md)
* [Interlude: Using Curl](04_4a_Interlude_Using_Curl.md)
* [4.5: Sending Coins with Automated Raw Transactions](04_5_Sending_Coins_with_Automated_Raw_Transactions.md)
* [4.6: Sending Other Types of Transactions](04_6_Sending_Coins_to_Other_Addresses.md)
* [5.0: Controlling Bitcoin Transactions](05_0_Controlling_Bitcoin_Transactions.md)
* [5.1 Watching for Stuck Transactions](05_1_Watching_for_Stuck_Transactions.md)
* [5.2: Resending a Transaction with RBF](05_2_Resending_a_Transaction_with_RBF.md)
* [5.3: Funding a Transaction with CPFP](05_3_Funding_a_Transaction_with_CPFP.md)
* [3.4: Understanding the Descriptor Wallet](03_4_Understanding_the_Descriptor_Wallet.md)
* [4.0: Preparing Your Bitcoin Addresses]
* [4.1: Understanding the Address](04_1_Understanding_the_Address.md)
* [4.2: Creating an Address from a Descriptor](04_2_Creating_an_Address_from_a_Descriptor.md)
* [4.3: Creating QR Codes for Addresses](04_3Creating_QR_Codes_for_Addresses.md)
* [4.4: Receiving a Transaction](04_4_Receiving_a_Transaction.md)
* [Interlude: Using Command-Line Variables](04_4a_Interlude_Using_Command-Line_Variables.md)
* [5.0: Sending Bitcoin Transactions](05_0_Sending_Bitcoin_Transactions.md)
* [5.1: Sending Coins the Easy Way](05_1_Sending_Coins_The_Easy_Way.md)
* [5.2: Creating a Raw Transaction](05_2_Creating_a_Raw_Transaction.md)
* [Interlude: Using JQ](05_2a_Interlude_Using_JQ.md)
* [5.3: Creating a Raw Transaction with Named Arguments](05_3_Creating_a_Raw_Transaction_with_Named_Arguments.md)
* [5.4: Sending Coins with Raw Transactions](05_4_Sending_Coins_with_a_Raw_Transaction.md)
* [Interlude: Using Curl](05_4a_Interlude_Using_Curl.md)
* [5.5: Sending Coins with Automated Raw Transactions](05_5_Sending_Coins_with_Automated_Raw_Transactions.md)
* [5.6: Sending Other Types of Transactions](05_6_Sending_Coins_to_Other_Addresses.md)
* [6.0: Controlling Bitcoin Transactions](06_0_Controlling_Bitcoin_Transactions.md)
* [6.1 Watching for Stuck Transactions](06_1_Watching_for_Stuck_Transactions.md)
* [6.2: Resending a Transaction with RBF](06_2_Resending_a_Transaction_with_RBF.md)
* [6.3: Funding a Transaction with CPFP](06_3_Funding_a_Transaction_with_CPFP.md)
### PART THREE: EXPANDING BITCOIN
* [6.0: Expanding Bitcoin Transactions with Multisigs](06_0_Expanding_Bitcoin_Transactions_Multisigs.md)
* [6.1: Creating a Multisig with Public Keys](06_1_Creating_Multisig_Public_Keys.md)
* [6.2o: Creating a Multisig with Descriptors](06_2_Creating_Multisig_Descriptors.md)
* [6.3: Spending a Transaction with a Multisig](06_3_Spending_a_Transaction_to_a_Multisig.md)
* [7.0: Expanding Bitcoin Transactions with Multisigs](07_0_Expanding_Bitcoin_Transactions_Multisigs.md)
* [7.1: Creating a Multisig with Public Keys](07_1_Creating_Multisig_Public_Keys.md)
* [7.2: Creating a Multisig with Descriptors](07_2_Creating_Multisig_Descriptors.md)
* [7.3: Spending a Transaction with a Multisig](07_3_Spending_a_Transaction_to_a_Multisig.md)
[in progress]
* [7.0: Expanding Bitcoin Transactions with PSBTs](07_0_Expanding_Bitcoin_Transactions_PSBTs.md)
* [7.1: Creating a Partially Signed Bitcoin Transaction](07_1_Creating_a_Partially_Signed_Bitcoin_Transaction.md)
* [Interlude: Creating Animated QR Codes](07_1a_Creating_Animated_QR_Codes.md) [**TO WRITE**]