mirror of
https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
synced 2026-02-16 14:12:48 +00:00
content on multiple wallets
This commit is contained in:
parent
6130e2061e
commit
2d2a74b120
@ -30,15 +30,22 @@ $ ls ~/.bitcoin/signet/wallets
|
||||
$
|
||||
```
|
||||
|
||||
That's because Bitcoin Core doesn't create a wallet by default, but creating one is quite simple. You just run `bitcoin-cli createwallet` and choose a name for your wallet, such as `"mainwallet"`.
|
||||
That's because Bitcoin Core doesn't create a wallet by default, but creating one is quite simple. You just run `bitcoin-cli createwallet` and choose a name for your wallet. If you choose no name (`""`) you're creating a wallet that will be loaded by default (which is helpful!). But you could also choose a real name like `"mainwallet"` if you plan to run multiple wallets. (We suggest the use of a no-name wallet for this tutorial, for reasons of simplicity, as we'll discuss later.)
|
||||
|
||||
Here's what the creation looks like:
|
||||
```
|
||||
$ bitcoin-cli createwallet "mainwallet"
|
||||
$ bitcoin-cli createwallet ""
|
||||
{
|
||||
"name": "mainwallet"
|
||||
"name": ""
|
||||
}
|
||||
```
|
||||
|
||||
Now, your `wallets` directory should be populated.
|
||||
If you created a `""` wallet, your `wallets` directory will have files in it:
|
||||
```
|
||||
wallet.dat wallet.dat-journal
|
||||
```
|
||||
|
||||
If you created a named wallet, the `wallets` directory will instead have a subdirectory by that name, and the subdirectory will have the files.
|
||||
```
|
||||
$ ls ~/.bitcoin/signet/wallets
|
||||
mainwallet
|
||||
@ -46,17 +53,17 @@ $ ls ~/.bitcoin/signet/wallets/mainwallet
|
||||
wallet.dat wallet.dat-journal
|
||||
```
|
||||
|
||||
As this indicates, each wallet will have its own directory. (The main directory is used if you choose `""` for your wallet name.) Each directory will then have a `wallet.dat` file (which is a SQLite database) and a `wallet.dat-journal` file (which is an SQLite rollback journal).
|
||||
Each wallet will have a `wallet.dat` file (which is a SQLite database) and a `wallet.dat-journal` file (which is an SQLite rollback journal).
|
||||
|
||||
You can also see details on your wallet with the `bitcoin-cli getwalletinfo` command:
|
||||
You can see details on your wallet with the `bitcoin-cli getwalletinfo` command:
|
||||
```
|
||||
$ bitcoin-cli getwalletinfo
|
||||
{
|
||||
"walletname": "mainwallet",
|
||||
"walletname": "",
|
||||
"walletversion": 169900,
|
||||
"format": "sqlite",
|
||||
"txcount": 0,
|
||||
"keypoolsize": 3999,
|
||||
"keypoolsize": 4000,
|
||||
"keypoolsize_hd_internal": 4000,
|
||||
"paytxfee": 0.00000000,
|
||||
"private_keys_enabled": true,
|
||||
@ -65,14 +72,14 @@ $ bitcoin-cli getwalletinfo
|
||||
"descriptors": true,
|
||||
"external_signer": false,
|
||||
"blank": false,
|
||||
"birthtime": 1770319097,
|
||||
"birthtime": 1770328126,
|
||||
"flags": [
|
||||
"last_hardened_xpub_cached",
|
||||
"descriptor_wallet"
|
||||
],
|
||||
"lastprocessedblock": {
|
||||
"hash": "00000010ea21796c6e54101bf757ca1e80d656856d1c71aa18282698edb4b49b",
|
||||
"height": 290276
|
||||
"hash": "0000000bd5046d28c2c02a60be14f2d3f1909277e574fa01279190dbe468a6e0",
|
||||
"height": 290283
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -86,7 +93,7 @@ The next thing you need to do is create an address for receiving payments. This
|
||||
|
||||
```
|
||||
$ bitcoin-cli getnewaddress
|
||||
tb1qhlcqx0rmqctujw94l2rw9r8umx7keerp38lc06
|
||||
tb1q480435stq22qx0npkfsl54j8v38r0fyz6w2zsu
|
||||
```
|
||||
Note that this address begins with an "tb1", which [means](https://en.bitcoin.it/wiki/List_of_address_prefixes) that it's a Bech32 address on either signet or testnet. The discussion of different address types in §4.1 will also talk about all of their identifying prefixes.
|
||||
|
||||
@ -96,7 +103,7 @@ Take careful note of the address. You'll need to give it to whomever will be sen
|
||||
|
||||
> :book: ***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. However 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 your `~/.bitcoin/signet /wallets/{walletname}/` directory. With a single address in hand, you could jump straight [§3.5: Receiving a Transaction](03_5_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.
|
||||
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.5: Receiving a Transaction](03_5_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
|
||||
|
||||
@ -129,9 +136,79 @@ If you want to lock your wallet back up earlier than that, you can use `bitcoin-
|
||||
$ bitcoin-cli walletlock
|
||||
```
|
||||
|
||||
## Optional: Proving Control
|
||||
## Optional: Reload Named Wallets
|
||||
|
||||
In previous versions of Bitcoin Core, you used to be able to prove control of an address with the `bicoin-cli signmessage` command. This is generally a nice feature because it allows you to assure someone sending you funds that they're sending to a place where you will definitely be able to retrieve the funds. 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 it's a complex process that goes beyond the scope of this course.
|
||||
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.
|
||||
```
|
||||
$ bitcoin-cli loadwallet mainwallet
|
||||
{
|
||||
"name": "mainwallet"
|
||||
}
|
||||
```
|
||||
But you can also make your named wallet load on start by adding a `true` to the end of the `bitcoin-cli loadwallet` command:
|
||||
```
|
||||
$ bitcoin-cli loadwallet mainwallet true
|
||||
{
|
||||
"name": "mainwallet"
|
||||
}
|
||||
```
|
||||
Afterward, the wallet that you must recently flagged in this way should always be the one that appaers at startup.
|
||||
|
||||
## Optional: Create Multiple Wallets
|
||||
|
||||
You can create multiple wallets if it's helpful for separating funds or separating different sorts of expenses:
|
||||
```
|
||||
$ bitcoin-cli createwallet "gamingfunds"
|
||||
{
|
||||
"name": "gamingfunds"
|
||||
}
|
||||
```
|
||||
bitcoin-cli listwallets` will list out all of the wallets currently "loaded", which will include your newly created one(s).
|
||||
```
|
||||
$ bitcoin-cli listwallets
|
||||
[
|
||||
"mainwallet",
|
||||
"gamingfunds"
|
||||
]
|
||||
```
|
||||
For commands that relate to the wallet (which is most of the ones you'll regularly use), you can specify which loaded wallet to use with the `-rpcwallet=` flag:
|
||||
```
|
||||
$ bitcoin-cli -rpcwallet=mainwallet getnewaddress
|
||||
tb1qdve6cqp05acjpm77d7le5d07haplhkcc3ucr3k
|
||||
```
|
||||
If you try to run a wallet-related command when you have multiple wallets loaded without using the `-rpcwallet=` flag, you'll get an error:
|
||||
```
|
||||
Multiple wallets are loaded. Please select which wallet to use by requesting the RPC through the /wallet/<walletname> URI path. Or for the CLI, specify the "-rpcwallet=<walletname>" option before the command (run "bitcoin-cli -h" for help or "bitcoin-cli listwallets" to see which wallets are currently loaded).
|
||||
```
|
||||
Rather than flagging every command, it's easier to use `bitcoin-cli unloadwallet` to unload the wallets that you're not currently using:
|
||||
```
|
||||
$ bitcoin-cli unloadwallet mainwallet
|
||||
{
|
||||
}
|
||||
$ bitcoin-cli listwallets
|
||||
[
|
||||
"gamingfunds"
|
||||
]
|
||||
```
|
||||
You can then use the `bitcoin-cli loadwallet` to bring a wallet back into active use, and use both commands to swap around what you're using:
|
||||
```
|
||||
$ bitcoin-cli loadwallet mainwallet
|
||||
{
|
||||
"name": "mainwallet"
|
||||
}
|
||||
$ bitcoin-cli unloadwallet gamingfunds
|
||||
{
|
||||
}
|
||||
$ bitcoin-cli listwallets
|
||||
[
|
||||
"mainwallet"
|
||||
]
|
||||
```
|
||||
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 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 assure someone sending you funds that they're sending to a place where you will definitely be able to retrieve the funds (or at least where 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.
|
||||
|
||||
Just keep in mind for the moment that proof of control is a nice feature if you can manage it.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user