mirror of
https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
synced 2025-06-07 16:06:26 +00:00
Update 3_3_Setting_Up_Your_Wallet.md
This commit is contained in:
parent
396ee26bf7
commit
2b9ee41d5e
@ -7,49 +7,52 @@ You're now ready to start working with Bitcoin. To begin with, you'll need to cr
|
||||
## Create an Address
|
||||
|
||||
The first 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`.
|
||||
|
||||
Theoretically, you could run it just by typing it on the command line:
|
||||
```
|
||||
$ bitcoin-cli getnewaddress
|
||||
n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf
|
||||
```
|
||||
However, this isn't best practice. Though your address _is_ saved away in your wallet for your future use, you could easily make a mistake if you were retyping or cutting it somewhere else. And then you're telling people to send money to somewhere else (or to nowhere!). So instead we suggest a best practice, which is meant to minimize address mistakes.
|
||||
|
||||
|
||||
```
|
||||
Note that this address begins with an "n" (or sometimes an "m"). This signifies that this is a testnet address.
|
||||
|
||||
> **TESTNET vs MAINNET:** The equivalent mainnet address would start with a 1.
|
||||
|
||||
We'll use this same technique for other bitcoin-cli results in the future; note that you could do it all by hand, instead of piping stuff in and out of variables ... but we really don't suggest it.
|
||||
A Bitcoin address is literally where you receive money. It's like an email address, but for funds. However unlike an email address, a Bitcoin address should be considered a single-use token: use it to receive funds just _once_. When you want to receive funds from someone else, 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. This can make it possibly to statistically figure out who you and your contacts are, no matter how careful you are. However, if you keep reusing the same address, then it becomes pretty easy to see who you.
|
||||
|
||||
However a Bitcoin address is also something else: a public key (or more precisely, the 160-bit has of a public key). The public key (or address) allows you to receive money, while an associated private key lets you spend money.
|
||||
|
||||
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/testnet3 directory. The `wallet.dat` file contains a considerable amount of data about prefeences and transactions, but most importantly, it contains all of the keypairs that you create on your local instance of Bitcoin: both the public key (which is to say the address, which you give people so that you can receive coins) and the private key (which is what you use to spend those coins). For the most part, you won't have to worry about that private key: `bitcoind` will use it as appropriate. However, this makes the `wallet.dat` file extremely important: if you lose it, you lose your private keys, and if you lose your private keys, you lose your funds!
|
||||
|
||||
With a single address in hand, you could jump straight to the next section, and begin receiving funds. However, before we get there, we're going to talk about a few other wallet commands that you might want to use in the future.
|
||||
|
||||
|
||||
## Optional: Sign a Message
|
||||
|
||||
Sometimes you'll need to prove that you control a Bitcoin address (or rather, that you control its private key). This is important because it lets people know that they're sending funds to the right persons. This can be done by using the `bitcoin-cli signmessage` command, in the form `bitcoin-cli signmessage [address] [message]`. For example:
|
||||
```
|
||||
$ bitcoin-cli signmessage "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf" "Hello, World"
|
||||
H3yMBZaFeSmG2HgnH38dImzZAwAQADcOiMKTC1fryoV6Y93BelqzDMTCqNcFoik86E8qHa6o3FCmTsxWD7Wa5YY=
|
||||
```
|
||||
Another person can then use the `bitcoin-cli verifymessage` command to verify the signature. He inputs the address in question, the signature, and the message:
|
||||
```
|
||||
$ bitcoin-cli verifymessage "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf" "H3yMBZaFeSmG2HgnH38dImzZAwAQADcOiMKTC1fryoV6Y93BelqzDMTCqNcFoik86E8qHa6o3FCmTsxWD7Wa5YY=" "Hello, World"
|
||||
true
|
||||
```
|
||||
If they all match up, then the other person knows that he can safely transfer funds to the person who signed the message by sending to the address:.
|
||||
|
||||
If some black hat was making up signatures, this would instead produce a negative result:
|
||||
```
|
||||
$ bitcoin-cli verifymessage "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf" "FAKEBZaFeSmG2HgnH38dImzZAwAQADcOiMKTC1fryoV6Y93BelqzDMTCqNcFoik86E8qHa6o3FCmTsxWD7Wa5YY=" "Hello, World"
|
||||
false
|
||||
```
|
||||
|
||||
## Optional: Capture the Private Key
|
||||
|
||||
The address lets you receive bitcoins, but to spend them, you'll need the address' private key. Again, this is all stored in your wallet, and it's not something that you usually need to worry about. But, if you do need it for some purpose (such as proving ownership from some other machine), then you can access the private key with the `bitcoin-cli dumpprivkey` command.
|
||||
```
|
||||
$ bitcoin-cli dumpprivkey "$NEW_ADDRESS_1"
|
||||
$ bitcoin-cli dumpprivkey "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf"
|
||||
cW4s4MdW7BkUmqiKgYzSJdmvnzq8QDrf6gszPMC7eLmfcdoRHtHh
|
||||
```
|
||||
We opted not to put this in a variable, because it's not something you want floating around ...
|
||||
If you think it's a pain to have to constantly retype (or recopy) that public address, we agree. It's also prone to errors, a topic that we'll address in the next section. IN the meantime, as long as you were careful, you should now have a private key.
|
||||
|
||||
## Optional: Sign a Message
|
||||
|
||||
You can also sign a message using your address. This verifies that the message for the address was signed by the person who knew the address' private key. You do this with `bitcoin-cli signmessage [address] [message]`. For example:
|
||||
```
|
||||
$ NEW_SIG_1=$(bitcoin-cli signmessage $NEW_ADDRESS_1 "Hello, World")
|
||||
$ echo $NEW_SIG_1
|
||||
H3yMBZaFeSmG2HgnH38dImzZAwAQADcOiMKTC1fryoV6Y93BelqzDMTCqNcFoik86E8qHa6o3FCmTsxWD7Wa5YY=
|
||||
```
|
||||
A recipient can verify the signature if he inputs the address, the signature, and the message.
|
||||
```
|
||||
$ bitcoin-cli verifymessage "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf" "H3yMBZaFeSmG2HgnH38dImzZAwAQADcOiMKTC1fryoV6Y93BelqzDMTCqNcFoik86E8qHa6o3FCmTsxWD7Wa5YY=" "Hello, World"
|
||||
true
|
||||
```
|
||||
If some black hat was making up signatures, they'd instead get a negative result:
|
||||
```
|
||||
$ bitcoin-cli verifymessage "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf" "FAKEBZaFeSmG2HgnH38dImzZAwAQADcOiMKTC1fryoV6Y93BelqzDMTCqNcFoik86E8qHa6o3FCmTsxWD7Wa5YY=" "Hello, World"
|
||||
false
|
||||
```
|
||||
|
||||
## Optional: Dump Your Wallet
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user