Edited Part 1 (for real this time)

This commit is contained in:
Shannon Appelcline 2017-03-02 16:18:48 -08:00 committed by GitHub
parent fe7ecbcab8
commit 2b814dfa97

View File

@ -257,34 +257,34 @@ Before you start playing with bitcoin, you should make sure that the bitcoind is
## Part One: Setting Up Your Wallet ## Part One: Setting Up Your Wallet
You're now ready to start working with Bitcoin. To begin with, you'll need to initiate your wallet with an address for receiving funds. You're now ready to start working with Bitcoin. To begin with, you'll need to create an address for receiving funds.
### Create an Address ### 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". 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: Theoretically, you could run it just by typing it on the command line:
``` ```
$ bitcoin-cli getnewaddress $ bitcoin-cli getnewaddress
n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf
``` ```
However, this isn't best practice; if you retype that address or cut and paste it, it would be easy to make a mistake. 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. 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.
#### BEST PRACTICES: Use Variables to Capture Addresses #### BEST PRACTICES: Use Variables to Capture Addresses
Instead, use your shell's built in variables to capture your address. Instead, use your shell's built-in variables to capture your address.
``` ```
$ unset NEW_ADDRESS_1 $ unset NEW_ADDRESS_1
$ NEW_ADDRESS_1=$(bitcoin-cli getnewaddress) $ NEW_ADDRESS_1=$(bitcoin-cli getnewaddress)
``` ```
These commands clear the NEW_ADDRESS_1 variable, then fill it with the results of the "bitcoin-cli getnewaddress" command. These commands clear the NEW_ADDRESS_1 variable, then fill it with the results of the `bitcoin-cli getnewaddress` command.
You can then use your shell's "echo" command to look at your (new) address: You can then use your shell's `echo` command to look at your (new) address:
``` ```
$ echo $NEW_ADDRESS_1 $ echo $NEW_ADDRESS_1
n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf
``` ```
Note that this address begins with an "n" (but sometimes an "m"). This signifies that this is a testnet address. 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. > **TESTNET vs MAINNET:** The equivalent mainnet address would start with a 1.
@ -292,26 +292,22 @@ We'll use this same technique for other bitcoin-cli results in the future; note
### Capture the Private Key ### Capture the Private Key
The address lets you receive bitcoins, but to spend them, you'll need the address' private key. That's achieved with the "bitcoin-cli dumpprivkey" command. The following extracts the address from the variable created by the best practices, above, them dumps the private key into another variable: 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.
``` ```
$ unset NEW_PRIV_KEY_1 $ bitcoin-cli dumpprivkey "$NEW_ADDRESS_1"
$ NEW_PRIV_KEY_1=$(bitcoin-cli dumpprivkey "$NEW_ADDRESS_1")
```
As usual, an echo will show you what you have:
```
$ echo $NEW_PRIV_KEY_1
cW4s4MdW7BkUmqiKgYzSJdmvnzq8QDrf6gszPMC7eLmfcdoRHtHh cW4s4MdW7BkUmqiKgYzSJdmvnzq8QDrf6gszPMC7eLmfcdoRHtHh
``` ```
Usually you would not want to share this with anyone! And, in fact, you might need to use other techniques to save it when you have real addresses, receiving real money in the future! We opted not to put this in a variable, because it's not something you want floating around ...
### Sign a Message ### Sign a Message
You can also sign a message using your address (and your bitcoind) without needing your private key on hand. You do this with "bitcoin-cli signmessage [address] [message]". For example: 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:
``` ```
$ bitcoin-cli signmessage $NEW_ADDRESS_1 "Hello, World" $ NEW_SIG_1=$(bitcoin-cli signmessage $NEW_ADDRESS_1 "Hello, World")
$ echo $NEW_SIG_1
H3yMBZaFeSmG2HgnH38dImzZAwAQADcOiMKTC1fryoV6Y93BelqzDMTCqNcFoik86E8qHa6o3FCmTsxWD7Wa5YY= H3yMBZaFeSmG2HgnH38dImzZAwAQADcOiMKTC1fryoV6Y93BelqzDMTCqNcFoik86E8qHa6o3FCmTsxWD7Wa5YY=
``` ```
This verifies that the message for the address was signed by the person who knew the address' private key. A recipient can verify it if he inputs the address, the signature, and the message. A recipient can verify the signature if he inputs the address, the signature, and the message.
``` ```
$ bitcoin-cli verifymessage "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf" "H3yMBZaFeSmG2HgnH38dImzZAwAQADcOiMKTC1fryoV6Y93BelqzDMTCqNcFoik86E8qHa6o3FCmTsxWD7Wa5YY=" "Hello, World" $ bitcoin-cli verifymessage "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf" "H3yMBZaFeSmG2HgnH38dImzZAwAQADcOiMKTC1fryoV6Y93BelqzDMTCqNcFoik86E8qHa6o3FCmTsxWD7Wa5YY=" "Hello, World"
true true
@ -324,7 +320,7 @@ false
### Summary: Setting Up Your Wallet ### Summary: Setting Up Your Wallet
You need to create an address to receive funds. We suggest using variables to capture your address and ensure that you receive your funds. Based on that address, you can also access a private key and sign messages. You need to create an address to receive funds. We suggest using variables to capture your address, to ensure that you give out the correct address in the future. Based on that address, you can also access a private key and sign messages.
## Part Two: Receiving a Transaction ## Part Two: Receiving a Transaction