Bitcoin

[Witness Jo]

2025/11/03

Bitcoin

Build Instructions

# there is a document about linux build instruction (./doc/build-unix.md)
$ cmake -B build
$ cd ./build
$ make
# if you need to install binaries
$ make install

Mining Instructions

Wallet setup for mining

To start mining on your regtest node, you need to have a wallet set up to receive mining rewards.

# If you use bitcoin as test node mode, You can modify the ".bitcoin/bitcoin.conf" file like below
# testnet=1

# Wallet commands
$ bitcoin-cli createwallet "mywallet"
$ bitcoin-cli listwallets
$ bitcoin-cli getwalletinfo

# Load your wallet when your wallet is already created
$ bitcoin-cli loadwallet "mywallet"

# Start mining to a new address of your wallet
$ YOUR_ADDRESS=$(bitcoin-cli getnewaddress)
$ echo $YOUR_ADDRESS >> ~/.bitcoin/mining_address.txt

# Or load an latest address from file (last line)
$ YOUR_ADDRESS=$(tail -n 1 ~/.bitcoin/mining_address.txt)

# It is only for regtest or testnet mode (It is a feature for testing purpose)
# Fist agument is number of blocks to mine
# Second argument is your bitcoin address to receive mining rewards
$ bitcoin-cli generatetoaddress 1 $YOUR_ADDRESS
# Mine 1..100 blocks to your address -> mininum 100 blocks are needed to spend mining rewards
$ bitcoin-cli generatetoaddress 100 $YOUR_ADDRESS

# Check your "hdkeypath" field if "m/84h/1h/0h/0/7" --> it is bech32 address and the wallet index is 7
$ bitcoin-cli getaddressinfo $YOUR_ADDRESS

# Check private key of the address you are mining to (be careful with private keys!)
# Look at the 7th entry (index 7) for the private key information
$ bitcoin-cli listdescriptors true | jq

# See mining rewards in your wallet
# total balance should increase after mining
$ bitcoin-cli getbalance
# each mined block reward
$ bitcoin-cli listreceivedbyaddress 1 true

Mining (Full Node)

# There is a document about mining instruction (./doc/mining.md)
$ bitcoind

Mining (RegTest)

# RegTest mode is for local testing purpose
# You can set up your own private bitcoin network
bitcoind -regtest
# or
CONF_FILE=~/.bitcoin/bitcoin.conf
cat > $CONF_FILE << 'EOF'
regtest=1

[regtest]
server=1
rpcuser=root
rpcpassword=root
rpcallowip=127.0.0.1
rpcbind=127.0.0.1
rpcport=8332
fallbackfee=0.00001
mintxfee=0.00001
txindex=1
EOF

bitcoind

Mining (TestNet)

# Setting up a full node is needed too large storage space (over 500GB)
# But testnet is having small storage space (around 50GB)
# If you want to set up test net node, run the following command
# It is enough to test bitcoin commands
$ bitcoind -testnet
# or
$ echo "testnet=1" >> ~/.bitcoin/bitcoin.conf
$ bitcoind

Bitcoin Directory Structure

witnessjo ~/.bitcoin  $ ls -al
total 27544
drwx------  5 witnessjo witnessjo     4096 Nov  3 22:59 .
drwx------ 45 witnessjo witnessjo     4096 Nov  3 23:11 ..
-rw-------  1 witnessjo witnessjo      221 Nov  3 22:59 banlist.json
-rw-------  1 witnessjo witnessjo        6 Nov  3 22:59 bitcoind.pid
drwx------  3 witnessjo witnessjo     4096 Nov  3 23:04 blocks
drwx------  2 witnessjo witnessjo     4096 Nov  3 22:59 chainstate
-rw-------  1 witnessjo witnessjo       75 Nov  3 22:59 .cookie
-rw-------  1 witnessjo witnessjo 28154187 Nov  3 23:11 debug.log
-rw-------  1 witnessjo witnessjo        0 Nov  3 22:59 .lock
-rw-------  1 witnessjo witnessjo     4210 Nov  3 22:59 peers.dat
-rw-------  1 witnessjo witnessjo      193 Nov  3 22:59 settings.json
drwx------  3 witnessjo witnessjo     4096 Nov  3 23:05 wallets

How to see the chainstate files (chainstate directory)

How to see the block files (blocks directory)

How to start bitcoin mining

Wallet Instructions

Create a new wallet

List wallets

Get wallet info

Load previously created wallet

Get more detailed information about wallet

Mining to a specific address and checking balance

Send bitcoin from your address to another address

HD Key Management

# Dump public key of your mining address
bitcoin-cli -regtest -rpcwallet=mywallet gethdkeys '{"private": false}' >> ~/.bitcoin/mining_public_keys.txt

Network Monitoring (Block Explorer)

btc-rpc-explorer

An Official blockchain explorer

# Before running btc-rpc-explorer, make sure your bitcoind is running with RPC server enabled.
# You need to set up config file (~/.bitcoin/bitcoin.conf) like below
#####################
# server=1
# rpcuser=root
# rpcpassword=root
# rpcallowip=127.0.0.1
# rpcbind=127.0.0.1


## for regtest network
# regtest=1 (for using regtest network as default)
#
# [regtest]
# rpcuser=root
# rpcpassword=root
# rpcallowip=127.0.0.1
# rpcbind=127.0.0.1
#####################

# And restart your bitcoind process
pkill bitcoind
bitcoind --daemon

# Or for regtest network
bitcoind -regtest -rpcport=8332 -port=8333

# Then run btc-rpc-explorer
# Default bitcoind rpc port is 8332
git clone https://github.com/janoside/btc-rpc-explorer
docker build -t btc-rpc-explorer ./btc-rpc-explorer
docker run -it --network host \
       -e BTCEXP_HOST=0.0.0.0 \
       -e BTCEXP_PORT=3002 \
       -e BTCEXP_BITCOIND_HOST=127.0.0.1 \
       -e BTCEXP_BITCOIND_PORT=8332 \
       -e BTCEXP_BITCOIND_USER=root \
       -e BTCEXP_BITCOIND_PASS=root \
       -e BTCEXP_BASIC_AUTH_PASSWORD="" \
       btc-rpc-explorer