This setup document provides instructions on how to set up reusable bash scripts for easily running Bitcoin Core on different networks: regtest, signet, testnet, and mainnet.
To get started:
- Clone this repository or the latest bitcoin sourcecode:
git clone <repo-url>
- Check the doc folder for specific build requirements for your operating system (Linux, macOS, Windows).
To validate the Bitcoin Core installation, run:
bitcoind -daemonThis should output Bitcoin Core starting. To stop the daemon, run:
bitcoin-cli stop-
Create a parent folder called
bitcoin-scriptsand a child folder inside calleddatadir:mkdir -p bitcoin-scripts/datadir
Replace
<PATH_TO_DATA_DIR>in the scripts below with the absolute path to thedatadirfolder. -
Create the following scripts inside the
bitcoin-scriptsfolder:btc-start-regtest-node.sh:
# Start a Bitcoin Core node in regtest mode #!/bin/bash bitcoind -regtest -printtoconsole -server -rpcuser=user -rpcpassword=password -rpcport=18332 -txindex=1 -debug=net -fallbackfee=0.0001 -datadir=<PATH_TO_DATA_DIR>
btc-regtest-cmd.sh:
# Run Bitcoin CLI commands in regtest mode #!/bin/bash bitcoin-cli -regtest --rpcuser=user --rpcpassword=password --rpcport=18332 $@
-
Make the scripts executable:
chmod +x btc-start-regtest-node.sh chmod +x btc-regtest-cmd.sh
-
Start the Bitcoin node:
./btc-start-regtest-node.sh
-
Open another terminal to run some test cli commands:
./btc-regtest-cmd.sh generate 1 # Generate 1 block, should return the block hash. ./btc-regtest-cmd.sh getblockcount # Get the current block count, should return a number
You can go through same steps by changing the network name on the bash file for your preferred network.
- Port Conflicts: Ensure the
rpcport(e.g.,18332) is not already in use. - Permission Errors: Ensure the scripts are executable (
chmod +x). - Incorrect Paths: Double-check the
datadirpath in the scripts.