Regtest Galore
This article is a way for me to collect a whole bunch of different ways you can fire up a regtest network and use it for local development, with a focus on using it for Android development.
-
On macOS
a. Simple regtest on the command line
b. Command line with Esplora
c. Esplora + Android Emulator
f. Esplora + Polar + Android Emulator -
On Linux
a. Simple regtest on the command line
b. Command line with Esplora
c. Esplora + Android Emulator
f. Esplora + Polar + Android Emulator
Requirements
-
Download and install bitcoind
-
Understand how to start bitcoind in regtest mode
bitcoind -chain=regtest
- Interact with it using
bitcoin-cli
bitcoin-cli -chain=regtest createwallet myregtestwallet
- Create an alias in your
.bashrc
or.zshrc
# .zshrc
alias bcr="bitcoin-cli -chain=regtest"
macOS
1. Simple regtest on the command line
bcr help
bcr createwallet myregtestwallet
bcr loadwallet myregtestwallet
bcr getnewaddress
bcr generatetoaddress 101 <address>
2. Regtest on the command line with Esplora
1. Download Esplora. Esplora is an electrs fork by Blockstream. Build it from source and add it to your path.
git clone https://github.com/blockstream/electrs
cd electrs
git checkout new-index
cargo build --release
mv ./target/release/electrs ~/mybinaries/
# make sure ~/mybinaries is on your path
electrs -vvvv --daemon-dir <your_bitcoind_directory> --network=regtest
2. Fire up an Esplora server. You should confirm that your bitcoin directory is at the location used below, and adjust the command if it is somewhere else.
cargo run --release --bin electrs -- -vvvv --daemon-dir ~/Library/Application\ Support/Bitcoin --network=regtest
Note: the Esplora server will not be active (network requests to it will fail) until you mine at least 1 block in your network. Don’t forget to go mine a block with your bitcoin daemon.
3. Test that the server is up an running.
curl 127.0.0.1:3002/blocks/tip/height
3. Regtest with Esplora for use on Android Emulator
1. Download Esplora. Esplora is an electrs fork by Blockstream. Build it from source and add it to your path.
git clone https://github.com/blockstream/electrs
cd electrs
git checkout new-index
cargo build --release
mv ./target/release/electrs ~/mybinaries/
# make sure ~/mybinaries is on your path
electrs -vvvv --daemon-dir <your_bitcoind_directory> --network=regtest
2. Fire up an Esplora server. You should confirm that your bitcoin directory is at the location used below, and adjust the command if it is somewhere else.
cargo run --release --bin electrs -- -vvvv --daemon-dir ~/Library/Application\ Support/Bitcoin --network=regtest
3. Use the Esplora url for your connection to the local server.
val regtestEsploraUrl: String = "http://10.0.2.2:3002"
4. Esplora + Polar + Android Emulator
- Fire up Polar
- Grab the IP address connection from the bitcoin core daemon (note that the port is often not the standard 18443 port)
- Start Esplora
electrs -vvvv --daemon-dir ~/.polar/networks/1/volumes/bitcoind/backend1/ --daemon-rpc-addr 127.0.0.1:18446 --network=regtest
Linux
1. Simple regtest on the command line
bcr help
bcr createwallet myregtestwallet
bcr loadwallet myregtestwallet
bcr getnewaddress
bcr generatetoaddress 101 <address>
2. Regtest on the command line with Esplora
1. Download Esplora. Esplora is an electrs fork by Blockstream. Build it from source and add it to your path.
git clone https://github.com/blockstream/electrs
cd electrs
git checkout new-index
cargo build --release
mv ./target/release/electrs ~/mybinaries/
# make sure ~/mybinaries is on your path
electrs -vvvv --daemon-dir <your_bitcoind_directory> --network=regtest
2. Fire up an Esplora server. You should confirm that your bitcoin directory is at the location used below, and adjust the command if it is somewhere else.
cargo run --release --bin electrs -- -vvvv --daemon-dir ~/.bitcoin --network=regtest
3. Test that the server is up an running.
curl 127.0.0.1:3002/blocks/tip/height
3. Regtest with Esplora for use on Android Emulator
1. Download Esplora. Esplora is an electrs fork by Blockstream. Build it from source and add it to your path.
git clone https://github.com/blockstream/electrs
cd electrs
git checkout new-index
cargo build --release
mv ./target/release/electrs ~/mybinaries/
# make sure ~/mybinaries is on your path
electrs -vvvv --daemon-dir <your_bitcoind_directory> --network=regtest
2. Fire up an Esplora server. You should confirm that your bitcoin directory is at the location used below, and adjust the command if it is somewhere else.
cargo run --release --bin electrs -- -vvvv --daemon-dir ~/.bitcoin --network=regtest
3. Use the Esplora url for your connection to the local server.
val regtestEsploraUrl: String = "http://10.0.2.2:3002"
4. Esplora + Polar + Android Emulator
- Fire up Polar
- Grab the IP address connection from the bitcoin core daemon (note that the port is often not the standard 18443 port)
- Start Esplora
electrs -vvvv --daemon-dir ~/.polar/networks/1/volumes/bitcoind/backend1/ --daemon-rpc-addr 127.0.0.1:18446 --network=regtest