git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin
git checkout 24.xmake 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.
./src/bitcoind -regtest -printtoconsole -rpcuser=user -fallbackfee=0.0001 -rpcpassword=passit will get stuck at something like
dnsseed thread exitjust 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 errorbitcoin 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./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass createwallet mywalletif 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/mywalletthe output would look like this:
{
"name": "mywallet",
"warning": ""
}./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass listwalletsthe output would look like:
[
"mywallet"
]If its an empty array, run the wallet creation command.
./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getnewaddressthis outputs an address like this:
bcrt1q8p2rr62m5esks25e62jgccurwwn0uauqyrtj44ADDR=$(./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getnewaddress)
./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass generatetoaddress 101 $ADDRit will mine 101 blocks and return their adresses in an array.
./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getbalanceit should show a balance like
50.00000000. Voila! you mined 50 bitcoins!
./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getblockcountshould return
101(or multiples of 101 if you ran the above commands multiple times)
./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./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass createwallet testwallet
ADDR2=$(./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getnewaddress)./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass generatetoaddress 101 $ADDR2./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass sendtoaddress $ADDR2 10you might se some error indicating
insufficient balance, just mine more blocks.
./src/bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getbalance