Skip to content

Instantly share code, notes, and snippets.

@Danilo-Araujo-Silva
Last active April 27, 2021 14:45
Show Gist options
  • Select an option

  • Save Danilo-Araujo-Silva/9dec9b83b3c22ab55049f9ede3f8ef6c to your computer and use it in GitHub Desktop.

Select an option

Save Danilo-Araujo-Silva/9dec9b83b3c22ab55049f9ede3f8ef6c to your computer and use it in GitHub Desktop.
full configuration for bitcoind with regtest and docker
regtest=1
[regtest]
debug=1
server=1
rpcallowip=0.0.0.0/0
rpcbind=127.0.0.1
rpcbind=bitcoind-regtest-01
rpcauth=<rpcuser>:<rpc auth line created by https://github.com/bitcoin/bitcoin/tree/c7ad94428ab6f54661d7a5441e1fdd0ebf034903/share/rpcauth>
# Used for inspecting transactions
txindex=1
regtest=1
[regtest]
debug=1
server=1
rpcallowip=0.0.0.0/0
rpcbind=127.0.0.1
rpcbind=bitcoind-regtest-02
rpcauth=<rpc auth line created using https://github.com/bitcoin/bitcoin/tree/c7ad94428ab6f54661d7a5441e1fdd0ebf034903/share/rpcauth>
# Using different ports from the previous container
# The default ones are: 18443 (rpcport), 18444 (port)
rpcport=18445
port=18446
connect=<first container ip, fetched from the docker network>:18444

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, ""]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment