6

I am getting into Bitcoin development and it seems that bitcoin regtest mode is perfect for testing our applications.

I am trying to create a network, following Fred Tingey's answer but, unfortunately, it's not working.

I need suggestions, what information can I provide? I am trying to use docker, but I have to first create 64-bit Ubuntu machine. Thanks

  • Sure: link – sbaha88 Feb 12 '15 at 13:49
  • I think I am not properly creating additional data directories. I can't connect to the network, the connection times out. @ShaunWilson – sbaha88 Feb 12 '15 at 13:50
  • Well the instructions in Fred's answer appear to be mostly correct, he does seem to list inconsistent port numbers. I'll see if i can clean it up. – Shaun Wilson Feb 12 '15 at 13:58
  • Thanks a lot. What I am struggling with is how to test if the network is working properly? Also, to create additional directories, is it just copy and paste? @ShaunWilson – sbaha88 Feb 12 '15 at 14:03
  • I cleaned up his answer, but it'll take a while for peer review to catch up to it. Yes, you can simply copy/paste folders to create more nodes. Once they are running and connected you can use the command-line interface to issue commands like getpeerinfo, for example sourceforge.net/p/bitcoin/mailman/message/32012030 – Shaun Wilson Feb 12 '15 at 14:44
6

It appears that Fred Tingey's answer was mostly correct, but contained incorrect port numbers in the samples he provided. If someone were to copy and paste it all it would not have worked correctly.

I've modified his answer, it is awaiting peer review.

The use of Ubuntu, Docker and VirtualBox shouldn't affect your ability to configure regtest.

You may have problems connecting from the host to the guest, if you do I suggest perhaps asking questions on superuser or ubuntu exchanges instead.

Hope that helps!

=== Here's the edited version:

In order to run multiple nodes in regtest mode on a single machine you will need to sandbox each node.

In this example I have three nodes, they are named Alice, Bob and Cory. Since Bitcoin is a Peer/Mesh network, my goal is to connect each nodes so that changes made to Cory are ultimately visible to Bob (without necessarily requiring a direct connection between the two.)

Step 1: Create folders for each node.

These folders will contain our data and configs for each node. The names are not important, they can be renamed later, so you can name them "Alice", "Bob" and "Cory" for now. Remember where you create them, you will need their paths for Step 3 below.

Step 2: In each folder, create a bitcoin.conf file

In the config files Alice will be configured to connect to Cory, and Bob will be configured to connect to Alice. In addition to configuring outbound connections, this is also where we specify regtest=1 and server=1 settings.

bitcoin.conf for Alice

regtest=1 server=1 # Alice connects to Cory connect=localhost:18333

bitcoin.con for Bob

regtest=1 server=1 # Bob connects to Alice connect=localhost:18444

bitcoin.conf for Cory

regtest=1 server=1 # Cory connects to nobody

Step 3: Start each node.

Note each node must have a different port number since only one node can bind to a port number at any time.

  • Alice on port 18444
  • Bob on port 18555
  • Cory on port 18333

You can choose your own port numbers of course, just be careful not to use a port number that is already in use by something else.

The command-line options will tell bitcoin what port number to use, where to store data, and where to find its config file:

Cory:

"C:\Program Files\Bitcoin\bitcoin-qt.exe" -conf="C:\Cory\bitcoin.conf" -datadir="C:\Cory" -port=18333 -rpcport=8333

Bob:

"C:\Program Files\Bitcoin\bitcoin-qt.exe" -conf="C:\Bob\bitcoin.conf" -datadir="C:\Bob" -port=18555 -rpcport=8555

Alice:

"C:\Program Files\Bitcoin\bitcoin-qt.exe" -conf="C:\Alice\bitcoin.conf" -datadir="C:\Alice" -port=18444 -rpcport=8444

This will launch three instances of the Bitcoin Client, and the folders for each node will begin to initialize with regtest data.

Step 4: Testing

You can use the Help->Debug Window->Console option to interactively execute commands on any of the nodes. For example, you can mine 101 blocks with the following bitcoin console command:

setgenerate true 101

You should (after a few seconds) then have been awarded coins.

These mining activities result in coinbase transactions - and only the last one of 50 BTC is available to spend. Now you can send some BTC to one of the other nodes. After a bit more mining such a transaction will be confirmed.

You can also use the console commands getpeerinfo and getinfo to check the network is set up correctly. One of them (Core wit port=18333) should have 'sync=true' in its peerinfo output, and all nodes should have the same "block height" regardless of which node is used for mining.

  • 1
    you don't need the -conf arguments btw... at least on linux. And you will need to add -rpcport=XXX to deconflict the rpc ports – DrEntropy Jul 12 '15 at 23:32
  • You have to use -listen=1 if you're setting -connect otherwise it won't accept incoming connections. – user3708202 Jan 26 '17 at 22:52
  • you have 2 Bobs in command line examples – whatever Nov 4 '17 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.