mirror of
https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
synced 2025-06-07 16:06:26 +00:00
updated aliases and how to check if your blockchain is loaded
This commit is contained in:
parent
f6b44515a7
commit
abe3e07ea1
@ -4,58 +4,54 @@
|
|||||||
|
|
||||||
Before you start playing with Bitcoin, you should ensure that everything is setup correctly.
|
Before you start playing with Bitcoin, you should ensure that everything is setup correctly.
|
||||||
|
|
||||||
## Check Your Aliases
|
## Create Your Aliases
|
||||||
|
|
||||||
The Bitcoin setup docs suggest creating a set of aliases. In case you didn't run through those docs, you can create them for your main Bitcoin user with the following command:
|
We suggest creating some aliases to make it easier to use Bitcoin.
|
||||||
|
|
||||||
|
You can do so by putting them in your `.bash_profile`.
|
||||||
```
|
```
|
||||||
cat >> ~/.bash_profile <<EOF
|
cat >> ~/.bash_profile <<EOF
|
||||||
alias btcdir="cd ~/.bitcoin/" #linux default bitcoind path
|
alias btcdir="cd ~/.bitcoin/" #linux default bitcoind path
|
||||||
alias bc="bitcoin-cli"
|
alias bc="bitcoin-cli"
|
||||||
alias bd="bitcoind"
|
alias bd="bitcoind"
|
||||||
alias btcinfo='bitcoin-cli getwalletinfo | egrep "\"balance\""; bitcoin-cli getnetworkinfo | egrep "\"version\"|connections"; bitcoin-cli getmininginfo | egrep "\"blocks\"|errors"'
|
alias btcinfo='bitcoin-cli getwalletinfo | egrep "\"balance\""; bitcoin-cli getnetworkinfo | egrep "\"version\"|connections"; bitcoin-cli getmininginfo | egrep "\"blocks\"|errors"'
|
||||||
alias btcblock="echo \\\`bitcoin-cli getblockcount 2>&1\\\`/\\\`wget -O - http://blockexplorer.com/testnet/q/getblockcount 2> /dev/null | cut -d : -f2 | rev | cut -c 2- | rev\\\`"
|
|
||||||
EOF
|
EOF
|
||||||
```
|
```
|
||||||
|
After you enter these aliases you can either `source .bash_profile` to input them or just log out and back in.
|
||||||
> :warning: **WARNING:** The btcblock alias will not work correctly if you try to place it in your .bash_profile by hand, rather than using the "cat" command as suggested. If you want to enter it by hand, you need to adjust the number of backslashes (usually from three each to one each), so make sure you know what you're doing if you aren't entering the commands exactly as suggested.
|
|
||||||
|
|
||||||
Note that these aliases includes shortcuts for running `bitcoin-cli`, for running `bitcoind`, and for going to the Bitcoin directory. These aliases are mainly meant to make your life easier. We suggest you create other aliases to ease your use of frequent commands (and arguments) and to minimize errors. Aliases of this sort can be even more useful if you have a complex setup where you regularly run commands associated with Mainnet, with Testnet, _and_ with Regtest, as explained further below.
|
Note that these aliases includes shortcuts for running `bitcoin-cli`, for running `bitcoind`, and for going to the Bitcoin directory. These aliases are mainly meant to make your life easier. We suggest you create other aliases to ease your use of frequent commands (and arguments) and to minimize errors. Aliases of this sort can be even more useful if you have a complex setup where you regularly run commands associated with Mainnet, with Testnet, _and_ with Regtest, as explained further below.
|
||||||
|
|
||||||
With that said, use of these aliases in _this_ document might accidentally obscure the core lessons being taught about Bitcoin, so the only aliases directly used here are `btcinfo` and `btcblock`, because they encapsulate much longer and more complex commands. Otherwise, we show the full commands; adjust for your own use as appropriate.
|
With that said, use of these aliases in _this_ document might accidentally obscure the core lessons being taught about Bitcoin, so the only alias directly used here is `btcinfo` because it encapsulatea much longer and more complex command. Otherwise, we show the full commands; adjust for your own use as appropriate.
|
||||||
|
|
||||||
> :link: **TESTNET vs MAINNET:** Remember that this tutorial generally assumes that you are using testnet. The `btcblock` alias needs to be slightly different on mainnet, where you can use the simpler "wget -O - http://blockchain.info/q/getblockcount 2>/dev/null".
|
|
||||||
|
|
||||||
## Run Bitcoind
|
## 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.
|
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
|
$ ps auxww | grep bitcoind
|
||||||
user1 29360 11.5 39.6 2676812 1601416 ? SLsl Feb23 163:42 /usr/local/bin/bitcoind -daemon
|
standup 455 1.3 34.4 3387536 1392904 ? SLsl Jun16 59:30 /usr/local/bin/bitcoind -conf=/home/standup/.bitcoin/bitcoin.conf
|
||||||
```
|
```
|
||||||
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).
|
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
|
## Verify Your Blocks
|
||||||
|
|
||||||
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.
|
You should have the whole blockchain downloaded before you start playing. Just run the `bitcoin-cli getblockcount` alias to see if it's all loaded.
|
||||||
|
```
|
||||||
|
$ bitcoin-cli getblockcount
|
||||||
|
1772384
|
||||||
|
```
|
||||||
|
That tells you what's loaded; you'll then need to check that against an online service that tells you the current block height.
|
||||||
|
|
||||||
If the two numbers aren't the same, you should wait:
|
> :book: ***What is Block Height?*** Block height is the the distance that a particular block is removed from the genesis block. The current block height is the block height of the newest block added to a blockchain.
|
||||||
```
|
|
||||||
$ 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:
|
You can do this by looking at a blocknet explorer, such as [the Blockcypher Testnet explorer](https://live.blockcypher.com/btc-testnet/). Does its most recent number match your `getblockcount`? If so, you're up to date.
|
||||||
```
|
|
||||||
$ btcblock
|
> :link: **TESTNET vs MAINNET:** Remember that this tutorial generally assumes that you are using testnet. If you're using the mainnet instead, you can retrieve the current block height with: `wget -O - http://blockchain.info/q/getblockcount 2>/dev/null`. Unfortunately, functionality like this for testnet has disappeared over the years.
|
||||||
1090099/1090099
|
|
||||||
```
|
If you're not up-to-date, but your `getblockcount` is increasing, no problem. Total download time can take from an hour to several hours, depending on your setup.
|
||||||
And that means you're ready to go!
|
|
||||||
|
|
||||||
## Optional: Know Your Server Types
|
## Optional: Know Your Server Types
|
||||||
|
|
||||||
> **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.
|
> **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:
|
The type of setup is mainly controlled through the ~/.bitcoin/bitcoin.conf file. If you're running testnet, it probably contains this line:
|
||||||
```
|
```
|
||||||
@ -69,6 +65,7 @@ However, if you want to run several different sorts of nodes simultaneously, you
|
|||||||
|
|
||||||
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).
|
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).
|
||||||
```
|
```
|
||||||
|
cat >> ~/.bash_profile <<EOF
|
||||||
alias bcstart="bitcoind -daemon"
|
alias bcstart="bitcoind -daemon"
|
||||||
alias btstart="bitcoind -testnet -daemon"
|
alias btstart="bitcoind -testnet -daemon"
|
||||||
alias brstart="bitcoind -regtest -daemon"
|
alias brstart="bitcoind -regtest -daemon"
|
||||||
@ -84,6 +81,7 @@ alias brdir="cd ~/.bitcoin/regtest" #linux default bitcoin regtest path
|
|||||||
alias bc="bitcoin-cli"
|
alias bc="bitcoin-cli"
|
||||||
alias bt="bitcoin-cli -testnet"
|
alias bt="bitcoin-cli -testnet"
|
||||||
alias br="bitcoin-cli -regtest"
|
alias br="bitcoin-cli -regtest"
|
||||||
|
EOF
|
||||||
```
|
```
|
||||||
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 reaches the next level.
|
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 reaches the next level.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user