mirror of
https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
synced 2025-06-07 16:06:26 +00:00
Fix: Typos in section 3
This commit is contained in:
parent
9131b22452
commit
e8efba8775
@ -29,12 +29,10 @@ With that said, use of these aliases in _this_ document might accidentally obscu
|
||||
## Run Bitcoind
|
||||
|
||||
You'll begin your exploration of the Bitcoin network with the `bitcoin-cli` command. However, bitcoind _must_ be running to use bitcoin-cli, as bitcoin-cli sends JSON-RPC commands to the bitcoind. If you used our standard setup, bitcoind should already be up and running. You can double check by looking at the process table.
|
||||
|
||||
```
|
||||
$ ps auxww | grep bitcoind
|
||||
user1 29360 11.5 39.6 2676812 1601416 ? SLsl Feb23 163:42 /usr/local/bin/bitcoind -daemon
|
||||
```
|
||||
|
||||
If it's not running, you'll want to run "/usr/local/bin/bitcoind -daemon" by hand and also place it in your crontab, as explained in [§2.1: Setting up a Bitcoin-Core VPS by Hand](02_1_Setting_Up_a_Bitcoin-Core_VPS_by_Hand.md).
|
||||
|
||||
## Verify Your Blocks
|
||||
@ -42,21 +40,17 @@ If it's not running, you'll want to run "/usr/local/bin/bitcoind -daemon" by han
|
||||
You should have the whole blockchain downloaded before you start playing. Just run the `btcblock` alias to see if it's all loaded. You'll see two numbers, which tell you how many blocks have loaded out of how many total.
|
||||
|
||||
If the two numbers aren't the same, you should wait:
|
||||
|
||||
```
|
||||
$ btcblock
|
||||
973212/1090099
|
||||
```
|
||||
|
||||
Total download time can take from an hour to several hours, depending on your setup.
|
||||
|
||||
If the two numbers are the same, you're fully loaded:
|
||||
|
||||
```
|
||||
$ btcblock
|
||||
1090099/1090099
|
||||
```
|
||||
|
||||
And that means you're ready to go!
|
||||
|
||||
## Optional: Know Your Server Types
|
||||
@ -64,21 +58,16 @@ And that means you're ready to go!
|
||||
> **TESTNET vs MAINNET:** When you set up your node, you choose to create it as either a Mainnet, Testnet, or Regtest node. Though this document presumes a testnet 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 testnet, it probably contains this line:
|
||||
|
||||
```
|
||||
testnet=1
|
||||
```
|
||||
|
||||
If you're running regtest, it probably contains this line:
|
||||
|
||||
```
|
||||
regtest=1
|
||||
```
|
||||
|
||||
However, if you want to run several different sorts of nodes simultaneously, you should leave the testnet (or regtest) flag out of your configuration file. You can then choose whether you're using the mainnet, the testnet, or your regtest every time you run bitcoind or bitcoin-cli.
|
||||
|
||||
Here's a set of aliases that would make that easier by creating a specific alias for starting and stopping the bitcoind, for going to the bitcoin directory, and for running bitcoin-cli, for each of the mainnet (which has no extra flags), the testnet (which is -testnet), or your regtest (which is -regtest).
|
||||
|
||||
```
|
||||
alias bcstart="bitcoind -daemon"
|
||||
alias btstart="bitcoind -testnet -daemon"
|
||||
@ -96,7 +85,6 @@ alias bc="bitcoin-cli"
|
||||
alias bt="bitcoin-cli -testnet"
|
||||
alias br="bitcoin-cli -regtest"
|
||||
```
|
||||
|
||||
For even more complexity, you could have each of your 'start' aliases use the -conf flag to load configuration from a different file. This goes far beyond the scope of this tutorial, but we offer it as a starting point for when your explorations of Bitcoin reach the next level.
|
||||
|
||||
## Summary: Verifying Your Bitcoin Setup
|
||||
|
@ -7,12 +7,10 @@ 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`.
|
||||
|
||||
```
|
||||
$ bitcoin-cli getnewaddress "" legacy
|
||||
n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf
|
||||
```
|
||||
|
||||
Note that this address begins with an "n" (or sometimes an "m"). This signifies that this is a testnet address.
|
||||
|
||||
The "legacy" flag is necessary to generate a traditional address, rather than a p2sh-segwit or bech32 address. The legacy address is currently required from the command line to make sure that signing works correctly.
|
||||
@ -32,27 +30,22 @@ With a single address in hand, you could jump straight to the next section and b
|
||||
## 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 person. This can be done by creating a signature with the `bitcoin-cli signmessage` command, in the form `bitcoin-cli signmessage [address] [message]`. For example:
|
||||
|
||||
```
|
||||
$ bitcoin-cli signmessage "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf" "Hello, World"
|
||||
H3yMBZaFeSmG2HgnH38dImzZAwAQADcOiMKTC1fryoV6Y93BelqzDMTCqNcFoik86E8qHa6o3FCmTsxWD7Wa5YY=
|
||||
```
|
||||
|
||||
You'll get the signature as a return.
|
||||
|
||||
_What is a signature?_ A digital signature is a combination of a message and a private key that can then be unlocked with a public key. Since there's a one-to-one correspendence between the elements of a keypair, unlocking with a public key proves that the signer controlled the corresponding private key.
|
||||
|
||||
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
|
||||
@ -61,13 +54,10 @@ false
|
||||
## Optional: Dump Your Wallet
|
||||
|
||||
It might seem dangerous having all of your irreplaceable private keys in a single file. That's what `bitcoin-cli backupwallet` is for. It lets you make a copy of your wallet.dat:
|
||||
|
||||
```
|
||||
$ bitcoin-cli backupwallet backup.dat
|
||||
```
|
||||
|
||||
You can then recover it with `bitcoin-cli importwallet`.
|
||||
|
||||
```
|
||||
$ bitcoin-cli importwallet backup.dat
|
||||
```
|
||||
@ -78,36 +68,30 @@ Sometimes, you might want to actually look at the private keys associated with y
|
||||
|
||||
To look at _all_ the keys in your wallet, type `bitcoin-cli ~/dumpwallet mywallet.txt`.
|
||||
To look at _all_ the keys in your wallet, type `bitcoin-cli dumpwallet ~/mywallet.txt`.
|
||||
|
||||
```
|
||||
$ bitcoin-cli dumpwallet ~/mywallet.txt
|
||||
{
|
||||
"filename": "/home/user1/mywallet.txt"
|
||||
}
|
||||
```
|
||||
|
||||
This will create a mywallet.txt file in your home directory with a long list of private keys, addresses, and other information. Mind you, you'd never want to put this data out in a plain text file on a Bitcoin setup with real funds!
|
||||
|
||||
More likely, you just want to look at the private key associated with a specific address. This can be done with the `bitcoin-cli dumpprivkey` command.
|
||||
|
||||
```
|
||||
$ bitcoin-cli dumpprivkey "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf"
|
||||
cW4s4MdW7BkUmqiKgYzSJdmvnzq8QDrf6gszPMC7eLmfcdoRHtHh
|
||||
```
|
||||
|
||||
You can then save that key somewhere safe, preferably somewhere not connected to the internet.
|
||||
|
||||
You can import any private key, from a wallet dump or an individual key dump, as follows:
|
||||
|
||||
```
|
||||
$ bitcoin-cli importprivkey cW4s4MdW7BkUmqiKgYzSJdmvnzq8QDrf6gszPMC7eLmfcdoRHtHh
|
||||
```
|
||||
|
||||
Expect this to take a while, as `bitcoind` needs to reread all past transactions, to see if there are any new ones that it should pay attention to.
|
||||
|
||||
> **NOTE:** Many modern wallets prefer [mnemonic codes](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) to generate the seeds necessary to create the private keys. This methodology is not used `bitcoin-cli`, so you won't be able to generate handy word lists to remember your private keys.
|
||||
|
||||
_You've been typing that Bitcoin address you generated a \_lot_, while you were signing messages and now dumping keys. If you think it's a pain, we agree. It's also prone to errors, a topic that we'll address in the very next section.\_
|
||||
_You've been typing that Bitcoin address you generated a _lot_, while you were signing messages and now dumping keys. If you think it's a pain, we agree. It's also prone to errors, a topic that we'll address in the very next section._
|
||||
|
||||
## Summary: Setting Up Your Wallet
|
||||
|
||||
|
@ -5,35 +5,27 @@
|
||||
The previous section demonstrated a number of command-line commands used without obfuscation or interference. However, that's often not the best way to run Bitcoin from the command line. Because you're dealing with long, complex, and unreadable variables, it's easy to make a mistake if you're copying those variables around (or, satoshi forfend, if you're typing them in by hand). Because those variables can mean the difference between receiving and losing real money, you don't _want_ to make mistakes. For these reasons, we strongly suggest using command-line variables to save addresses, signatures, or other long strings of information whenever it's reasonable to do so.
|
||||
|
||||
If you're using `bash`, you can save information to a variable like this:
|
||||
|
||||
```
|
||||
$ VARIABLE=$(command)
|
||||
```
|
||||
|
||||
That's a simple command substitution, the equivalent to `` VARIABLE=`command` ``. The command inside the parentheses is run, then assigned to the VARIABLE.
|
||||
That's a simple command substitution, the equivalent to ``VARIABLE=`command` ``. The command inside the parentheses is run, then assigned to the VARIABLE.
|
||||
|
||||
To create a new address would then look like this:
|
||||
|
||||
```
|
||||
$ unset NEW_ADDRESS_1
|
||||
$ NEW_ADDRESS_1=$(bitcoin-cli getnewaddress)
|
||||
```
|
||||
|
||||
These commands clear the NEW_ADDRESS_1 variable, just to be sure, 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:
|
||||
|
||||
```
|
||||
$ echo $NEW_ADDRESS_1
|
||||
n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf
|
||||
```
|
||||
|
||||
Because you have your address in a variable, you can now easily sign a message for that address, without worrying about mistyping the address. You'll of course save that signature into a variable too!
|
||||
|
||||
```
|
||||
$ NEW_SIG_1=$(bitcoin-cli signmessage $NEW_ADDRESS_1 "Hello, World")
|
||||
```
|
||||
|
||||
The rest of this tutorial will use this style of saving information to variables when it's practical.
|
||||
|
||||
_When is it not practical to use command-line variables?_ Command-line variables aren't practical if you need to use the information somewhere other than on the command line. For example, saving your signature may not actually be useful if you're just going to have to send it to someone else in an email. In addition, some future commands will output JSON objects instead of simple information, and variables can't be used to capture that information ... at least not without a _little_ more work.
|
||||
|
@ -17,12 +17,10 @@ _What is a transaction?_ A transaction is a bitcoin exchange. The owner of some
|
||||
## Verify Your Money
|
||||
|
||||
After you've requested your money, you should be able to verify it with the 'bitcoin-cli getbalance' command:
|
||||
|
||||
```
|
||||
$ bitcoin-cli getbalance
|
||||
0.00000000
|
||||
```
|
||||
|
||||
But wait, there's no balance yet!?
|
||||
|
||||
Welcome to the world of Bitcoin latency.The problem is that your transaction hasn't yet been recorded in a block!
|
||||
@ -32,12 +30,10 @@ _What is a block?_ Transactions are transmitted across the network and gathered
|
||||
_What is a miner?_ A miner is a participant of the Bitcoin network who works to create blocks. It's a paying job: when a miner successfully creates a block, he is paid a one-time reward plus the fees for the transactions in his block. Mining is big business. Miners tend to run on special hardware, accelerated in ways that make it more likely that they'll be able to create blocks. They also tend to be part of mining pools, where the miners all agree to share out the rewards when one of them successfully creates a block.
|
||||
|
||||
Fortunately, `bitcoin-cli getunconfirmedbalance` should still show your updated balance as long as the initial transaction has been created:
|
||||
|
||||
```
|
||||
$ bitcoin-cli getunconfirmedbalance
|
||||
0.47000000
|
||||
```
|
||||
|
||||
If that's still showing a zero too, you're probably moving through this tutorial too fast. Wait a second. The coins should show up unconfirmed, then rapidly move to confirmed. Do note that a coin can move from unconfirmedbalance to confirmedbalance almost immediately, so make sure you check both. However, if your `getbalance` and your `getunconfirmedbalance` both still show zero in ten minutes, then there's probably something wrong with the faucet, and you'll need to pick another.
|
||||
|
||||
### Gain Confidence in Your Money
|
||||
@ -47,14 +43,12 @@ You can use `bitcoin-cli getbalance "*" [n]` to see if a confirmed balance is 'n
|
||||
_What is block depth?_ After a block is built and confirmed, another block is built on top of it, and another ... Because this is a stochastic process, there's some chance for reversal when a block is still new. Thus, a block has to be buried several blocks deep in a chain before you can feel totally confident in your funds. Each of those blocks tends to be built in an average of 10 minutes ... so it usually takes about an hour for a confirmed transaction to receive full confidence.
|
||||
|
||||
The following shows that our transaction has been confirmed one time, but not twice:
|
||||
|
||||
```
|
||||
$ bitcoin-cli getbalance "*" 1
|
||||
0.47000000
|
||||
$ bitcoin-cli getbalance "*" 2
|
||||
0.00000000
|
||||
```
|
||||
|
||||
Obviously, every ten minutes or so this depth will increase.
|
||||
|
||||
Of course, on the testnet, no one is that worried about how reliable your funds are. You'll be able to spend your money as soon as it's confirmed.
|
||||
@ -62,7 +56,6 @@ Of course, on the testnet, no one is that worried about how reliable your funds
|
||||
## Verify Your Wallet
|
||||
|
||||
The `bitcoin-cli getwalletinfo` command gives you more money on the balance of your wallet:
|
||||
|
||||
```
|
||||
$ bitcoin-cli getwalletinfo
|
||||
{
|
||||
@ -81,7 +74,6 @@ $ bitcoin-cli getwalletinfo
|
||||
## Discover Your Transaction ID
|
||||
|
||||
Your money came into your wallet via a transaction. You can discover that transactionid (txid) with the `bitcoin-cli listtransactions` command:
|
||||
|
||||
```
|
||||
$ bitcoin-cli listtransactions
|
||||
[
|
||||
@ -105,11 +97,9 @@ $ bitcoin-cli listtransactions
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
This shows one transaction ("88e5d5f3077517d76f5a61491fa52e6aaae078c52bc62d849f09507ef0cfada2") that was received ("receive") by a specific address in my wallet ("n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf") for a specific amount ("0.47000000").
|
||||
|
||||
You can access similar information with the `bitcoin-cli listunspent` command, but it only shows the transactions for the money that you haven't spent. These are called UTXOs, and will be vitally important when you're sending money back out into the Bitcoin world:
|
||||
|
||||
```
|
||||
$ bitcoin-cli listunspent
|
||||
[
|
||||
@ -126,7 +116,6 @@ $ bitcoin-cli listunspent
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
Note that bitcoins are not just a homogeneous mess of cash jammed into your pocket. Each individual transaction that you receive or that you send is placed into the immutable blockchain ledger, in a block. You can see these individual transactions when you look at your unspent money. This means that bitcoin spending isn't quite as anonymous as you'd think. Though the addresses are fairly private, transactions can be examined as they go in and out of addresses. This makes privacy vulnerable to statistical analysis. It also introduces some potential non-fungibility to bitcoins, as you can track back through series of transactions, even if you can't track a specific "bitcoin".
|
||||
|
||||
_Why are all of these bitcoin amounts in fractions?_ Bitcoins are produced slowly, and so there are relatively few in circulation. As a result, each bitcoin over on the mainnet is worth quite a bit (~ $1,000 at the time of this writing). This means that people usually work in fractions. In fact, .47 BTC would be quite a lot in the real-world. You'll often be dealing with even smaller fractions on mainnet. For this reason, names have appeared for smaller amounts of bitcoins, including millibitcoins or mBTCs (one-thousandth of a bitcoin), microbitcoins or bits or μBTCs (one-millionth of a bitcoin), and satoshis (one hundred millionth of a bitcoin).
|
||||
@ -134,14 +123,11 @@ _Why are all of these bitcoin amounts in fractions?_ Bitcoins are produced slowl
|
||||
## Examine Your Transaction
|
||||
|
||||
You can get more information on a transaction with the `bitcoin-cli getrawtransaction` command:
|
||||
|
||||
```
|
||||
$ bitcoin-cli getrawtransaction "88e5d5f3077517d76f5a61491fa52e6aaae078c52bc62d849f09507ef0cfada2"
|
||||
010000000133261a25b44689bab2c6a207381ca21d243de9bbf21f0fa40c3a26ba7282a87b000000006b483045022100a2640761810dfc34dabed599928243afe24e13f520f780ceb382843a530a577c022050b92f5d9843d70ddb60a0aa294938862f2b7372818d6149ffd4f6adec5cf6c80121034dcaa515c2fda0f4a50b90a6d798e01c00a870bef0bd97154066fe202d2b5d75feffffff02c029cd02000000001976a914fd67e8a7c7813e7a5c376eb71074f373d924d96888ac17791703000000001976a914e176ee39c642344df2180863e27e2e936307273c88ac07a41000
|
||||
```
|
||||
|
||||
Granted, this isn't super useful, because it's the hex-encoded transaction data. Fortunately, you can get a more verbose description just by adding a '1' to your command:
|
||||
|
||||
```
|
||||
$ bitcoin-cli getrawtransaction "88e5d5f3077517d76f5a61491fa52e6aaae078c52bc62d849f09507ef0cfada2" 1
|
||||
{
|
||||
@ -197,7 +183,6 @@ $ bitcoin-cli getrawtransaction "88e5d5f3077517d76f5a61491fa52e6aaae078c52bc62d8
|
||||
"blocktime": 1488307692
|
||||
}
|
||||
```
|
||||
|
||||
Now you can see the full information on the transaction, including all of the inputs ("vin") and all the outputs ("vout). One of the interesting things to note is that although we received .47 BTC in the transaction, another .51869975 was sent to another address. That was probably a change address, a concept that is explored in the next section. It is quite typical for a transaction to have multiple inputs and/or multiple outputs.
|
||||
|
||||
> **WARNING:** These commands will not work in some situations. To be able to view a raw transaction on a standard node, some of the money must be unspent, or the transaction must still be in your mempool — which means that this command will work fine for the money you've just received, but not for old stuff. If you want to be able to view older transactions that have been spent, you can do so by maintaining a set of all transactions with the txindex=1 configuration, which is what our scripts suggest for all non-pruned instances. (You can't maintain a transaction index if your node is pruned.)
|
||||
|
Loading…
x
Reference in New Issue
Block a user