01- Create two different docker containers (there are bitcoin.conf examples below) bitcoind-regtest-01
and bitcoind-regtest-02
pointing to different data folders (The regtest network will only work with at least 2 nodes).
bitcoind -conf=/path/to/bitcoind-regtest-01/bitcoin.conf -datadir=/path/to/bitcoind-regtest-01/data/folder -daemon
bitcoind -conf=/path/to/bitcoind-regtest-02/bitcoin.conf -datadir=/path/to/bitcoind-regtest-02/data/folder -daemon
02- Create a docker network with the 2 containers
docker network create bitcoind-regtest-network
docker network connect bitcoind-regtest-network bitcoind-regtest-01
docker network connect bitcoind-regtest-network bitcoind-regtest-02
03- Get the ip address of the bitcoind-regtest-01
container in the network and change the bitcoind-regtest-02
bitcoin.conf
accordingly (since the bitcoind-regtest-02
node should be connecting to bitcoind-regtest-01
). If this step is not done
the getblocktemplate
method will not work.
docker network inspect bitcoind-regtest-network
04- Start the containers, observe the logs and check if there are no connection problems there
05- From the host machine (outside of the containers) export some environment variables (only used for testing purposes):
rpc_user_pass="<rpc_user>:<rpc_password>"
bitcoind_regtest_1_url="http://<bitcoind-regtest-01 ip address in the bitcoind-regtest-network>:<bitcoind-regtest-01 rcp port>/"
bitcoind_regtest_2_url="http://<bitcoind-regtest-01 ip address in the bitcoind-regtest-network>:<bitcoind-regtest-01 rcp port>/"
command_1="curl --user $rpc_user_password --data-binary \"{\\\"jsonrpc\\\": \\\"1.0\\\", \\\"id\\\": \\\"curltest\\\", \\\"method\\\": \\\"\$method\\\", \\\"params\\\": \$params }\" -H \"content-type: text/plain;\" $bitcoind_regtest_1_url"
command_2="curl --user $rpc_user_password --data-binary \"{\\\"jsonrpc\\\": \\\"1.0\\\", \\\"id\\\": \\\"curltest\\\", \\\"method\\\": \\\"\$method\\\", \\\"params\\\": \$params }\" -H \"content-type: text/plain;\" $bitcoind_regtest_2_url"
06- Test if it is working (a valid ouput should appear in both commands):
- method="getblockchaininfo" && params="[]" && eval "$command_1"
- method="getblockchaininfo" && params="[]" && eval "$command_2"
07- Check if the bitcoind-regtest-01
node has an connections_in
connection with the other one:
method="getnetworkinfo" && params="[]" && eval "$command_1"
08- Check if the bitcoind-regtest-02
node has an connections_out
connection with the other one:
method="getnetworkinfo" && params="[]" && eval "$command_2"
09- Probably no wallet is loaded yet, so let's check it
method="getwalletinfo" && params="[]" && eval "$command_1"
- The output should be something like:
{"result":null,"error":{"code":-18,"message":"No wallet is loaded. Load a wallet using loadwallet or create a new one with createwallet. (Note: A default wallet is no longer automatically created)"},"id":"curltest"}
10- Create a wallet if there's no one available (https://bitcoincore.org/en/doc/0.21.0/rpc/wallet/createwallet/):
method=createwallet && params='["/path/inside/the/container/or/shared/volume/where/you/want/to/store/the/wallet/regtest-01", false, false, "<wallet password here>", false, false, false]' && eval "$command_1"
11- Use the getwalletinfo
method again, if the wallet is not loaded, load it with
method="loadwallet" && params='["/path/inside/the/container/or/shared/volume/where/you/want/to/store/the/wallet/regtest-01"]' && eval "$command_1"
- Check if the wallet is loaded properly with the
getwalletinfo
method.
12- method="getnewaddress" && params="[]" && eval "$command_1"
13- `method="generatetoaddress" && params='[10, ""]'
14- TODO, complete documentation with other instructions from here: https://bitcoin.stackexchange.com/questions/17553/is-there-a-sandbox-in-bitcoin-for-testing/102885#102885
15- Remember that after mining the block, generate more 100 blocks so we can see the values in the balance properly.