Table of Contents
Set up a Local Bitcoin Node
The first step to setting up a miner is setting up a local bitcoin node using bitcoind.
More information about what it means to run a full bitcoin node, instructions for downloading and setting it up on each operating system, and various configuration options are all outlined on bitcoin.org.
Once you download the software, it is good practice to verify the release signatures to make sure the software was not modified or changed from its original state. PGP signatures can be verified with Gpg4win on Windows and gpg on Linux .
Note: Signature verification is very important to learn when running applications like bitcoind, especially on mainnet. If someone were to modify the code and insert something malicious, then you would see the signatures do not match and know not to run it.
Bitcoind System Requirements
A local bitcoin node runs as a command-line application (CLI) by default, and there are additional instructions on how to add a graphical user interface (GUI) depending on your operating system.
Note: This tutorial assumes you are using the CLI version, and anyone using the GUI (bitcoin-qt on Linux or Bitcoin Core on Windows) will need to adapt the instructions for their own setup. The bitcoin.conf file used by the GUI should be accessible via the settings / preferences panel.
The bitcoin testnet currently requires 30-40gb of storage, and the bitcoin mainnet requires upwards of 350gb of storage.
Please consider this requirement for both storage space and network quality when selecting where to run a node, as it will be required to download all past transactions on the blockchain.
Bitcoind Configuration File
When starting up bitcoind
you can use a configuration file to simplify the process and create a consistent result.
Instead of running a command like:
bitcoind -printtoconsole -server=1 -rpcuser=username -rpcpassword=password -txindex=0 -listen=1 -rpcserialversion=0 -maxorphantx=1 -banscore=1 -bind=0.0.0.0:18333 -rpcbind=0.0.0.0:18332 -rpcport=18332
You can simply run bitcoind -conf=path/to/bitcoin.conf
and let it use the values from the configuration file.
# [core]
# uncomment daemon to run in the background
# NOTE: not supported on Windows
# daemon=1
txindex=1
prune=0
maxorphantx=1
banscore=1
# [rpc]
server=1
rpcserialversion=0
rpcuser=your-bitcoind-username
rpcpassword=your-bitcoind-password
rpcallowip=127.0.0.1
# use the below settings at your own risk, as it
# opens up bitcoind to access from any IP address
# rpcallowip=0.0.0.0/0
# rpcallowip=::/0
Interacting with Bitcoind
Verify Bitcoind is Running
Note: On Windows, you can verify the process is running by opening the task manager (CTRL + Shift + Esc) and searching for the process name `bitcoind` under details. The commands in this section were written for Mac, Linux, or Windows WSL users.
Search for the bitcoind process using ps
:
ps -ax | grep bitcoin | grep -v grep
Which will output something similar to:
1969 ? Ssl 80:26 bitcoind
Here we can see bitcoind is running. If it did not appear, then you need to start your bitcoin node again.
Check Open Ports
Note: The commands in this section were written for Mac, Linux, or Windows WSL users.
You can check the open ports in use by bitcoind using lsof
.
lsof -i -P -n | grep LISTEN | grep bitcoind
Which will output something similar to:
bitcoind 1969 whoabuddy 10u IPv4 26807 0t0 TCP 127.0.0.1:8332 (LISTEN)
Using bitcoin-cli
The easiest way to interact with bitcoind
is to use bitcoin-cli
. There are various commands available to interact with the bitcoind daemon.
Note: Much more information and a full list of commands is available on the developer.bitcoin.org RPC API Reference
Description | Command |
---|---|
Get blockchain info including sync progress | getblockchaininfo |
Import wallet address for checking UTXOs | importaddress |
Import private key for making transactions | importprivkey |
Get wallet info | getwalletinfo |
See wallet transactions | listunspent |
See adresses in wallet | listaddressgroupings |
Stop bitcoind | stop |
Note: all commands above require using the correct flags with bitcoin-cli so that it knows how to interact with bitcoind. All configuration values below must match your configuration in bitcoin.conf.
For example, the command below would be used with importprivkey
above.
bitcoin-cli -rpcport=8332 -rpcuser=user -rpcpassword=password -rpcclienttimeout=7200 importprivkey "wif-formatted-private-key"
Remember to replace the rpcport, rpcuser, and rpcpassword values with the same values you used in your bitcoin.conf
file.
View more information about importing your address into bitcoind on the Stacks Keychain instructions.
Bash Alias Function
In the same way we use bitcion.conf
to prevent using a long command every time we start bitcoind
, we can create a bash alias function to make running bitcoin-cli
much simpler.
Note: The commands in this section were written for Mac, Linux, or Windows WSL users.
Instead of running a command like:
bitcoin-cli -rpcport=8332 -rpcuser=user -rpcpassword=password getblockchaininfo
You can simply run bitcoin-cli-stx getblockchaininfo
and it will automatically fill in the configuration values.
To setup a custom function, back up and then edit the .bashrc
file with your editor of choice.
cp .bashrc .bashrc-backup
nano .bashrc
Add the following code to the end of the file, and save your changes.
# function to simplify using bitcoin-cli
bitcoin-cli-stx() {
# prefills testnet and rpc port info
bitcoin-cli -rpcport=8332 -rpcuser=user -rpcpassword=password "$@"
}
Remember to replace the rpcport, rpcuser, and rpcpassword values with the same values you used in your bitcoin.conf
file.
Close and open the terminal, then test out the command:
bitcoin-cli-stx getblockchaininfo
Other Resources
Bitcoin Node
Stacks Keychain
Stacks Node