Skip to content

Instantly share code, notes, and snippets.

@rohansen856
Created October 24, 2025 10:23
Show Gist options
  • Select an option

  • Save rohansen856/ae1cee4e678e808ed61a6f7bbdbe906f to your computer and use it in GitHub Desktop.

Select an option

Save rohansen856/ae1cee4e678e808ed61a6f7bbdbe906f to your computer and use it in GitHub Desktop.
Bitcoin Core setup in Regtest mode

Clone the bitcoin core repo and switch to a stable release

git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin
git checkout 24.x

Compile bitcoin protocol network

make clean
./configure --with-gui=no --enable-wallet --with-incompatible-bdb
make -j$(nproc)

it will take quite a time... roughly 5 mins to be done. some warnings might spin up but ignore them.

Start a regtest node

./src/bitcoind -regtest -printtoconsole -rpcuser=user -fallbackfee=0.0001 -rpcpassword=pass

it will get stuck at something like dnsseed thread exit just wait for some moments (60 seconds to be exact), some more logs would show up. Now the node is up and this creates a one-node blockchain. if it shows an error bitcoin core is already running:

./src/bitcoind -regtest -printtoconsole -rpcuser=user -fallbackfee=0.0001 -rpcpassword=pass 

Error: Cannot obtain a lock on data directory /home/rcsen/.bitcoin/regtest. Bitcoin Core is probably already running.

Just stop the previously running one:

bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass stop

Create a wallet

./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass createwallet mywallet

if you have run it once before, it would throw an error like the following:

pass createwallet mywallet
error code: -4
error message:
Wallet file verification failed. Failed to create database path '/home/rcsen/.bitcoin/regtest/wallets/mywallet'. Database already exists.

in this case, remove the existing wallet and run the wallet creation command again:

# replace with your specific path
rm -rf /home/rcsen/.bitcoin/regtest/wallets/mywallet

the output would look like this:

{
  "name": "mywallet",
  "warning": ""
}

List all wallets

./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass listwallets

the output would look like:

[
  "mywallet"
]

If its an empty array, run the wallet creation command.

Generate an address (for wallet)

./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getnewaddress

this outputs an address like this:

bcrt1q8p2rr62m5esks25e62jgccurwwn0uauqyrtj44

Mine 101 blocks

ADDR=$(./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getnewaddress)
./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass generatetoaddress 101 $ADDR

it will mine 101 blocks and return their adresses in an array.

Confirm wallet balance

./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getbalance

it should show a balance like 50.00000000. Voila! you mined 50 bitcoins!

Check the block count

./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getblockcount

should return 101 (or multiples of 101 if you ran the above commands multiple times)

Check one block

./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getblockhash 1
# Put the hash derived from the above command (ex.: 586d576f52c2ca9602cc318057a1b92deb35284445d65b20f5979c74878916fc) to the below one
./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getblock <that-hash> 2

Generate a 2nd address (another wallet)

./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass createwallet testwallet
ADDR2=$(./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getnewaddress)

Mine some blocks to get balance

./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass generatetoaddress 101 $ADDR2

Send some balance to anothe address

./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass sendtoaddress $ADDR2 10

you might se some error indicating insufficient balance, just mine more blocks.

Check 2nd wallet balance

./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getbalance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment