Setting up a Regtest environment
For learning or testing purposes, it's safer and cheaper to use Bitcoin's test network --testnet (for more information, refer to https://bitcoin.org/en/glossary/testnet) or regression test mode --regtest (for more information, refer to https://bitcoin.org/en/glossary/regression-test-mode). We learned in the previous chapter how to use the Testnet network but this option stil requires us to download the blockchain and wait for delayed validation. However, there is a solution, and this time we are going to use the Bitcoin client in Regtest mode.
In this mode, we can set up a local testing network and a private blockchain whereby we can instantly validate transactions and create new bitcoins locally. Similar to running a web application in localhost mode, you'll find the Regtest option more suitable for developing and testing new applications.
You have to follow the same procedure as in the previous chapter and add an extra step: change bitcoin.conf to select the Regtest network by defining the parameter regtest=1.
Your bitcoin.conf will look like the following:
rpcuser=<user>
rpcpassword=<password>
#testnet=1
#prune=550
regtest=1
server=1
We commented out the testnet and prune parameters as they are no longer needed for Regtest mode. In addition, make sure to replace the RPC credentials <user/password> and use them throughout this section when they are needed.
datadir
port (default: 8443)
rpcport(default: 18442)
You can find more information about the Bitcoin Regtest mode in the official documentation at https://bitcoin.org/en/developer-examples#regtest-mode.