Having private Monero testnet network can be very useful, as you can play around with Monero without risking making expensive mistakes on real network. However, it is not clear how to set up a private testnet network. In this example, this is demonstrated.
The example was executed on Xubuntu 16.04 x64 using Monero 0.10.1. Instructions on how to compile Monero are avaliable here: compile-monero-09-on-ubuntu.
The testnet Monero network will include 3 nodes, each with its own blockchain database and a corresponding wallet on a single computer. The three testnet nodes will be listening at the following ports 28080, 38080 and 48080, respectively.
The example is based on the following reddit posts:
- How do I make my own testnet network, with e.g. two private nodes and private blockchain?
- Does unlocking balance in testnet mode differers from the normal mode?
Also much thanks go to reddit's user o--sensei for help with setting up the initial testnet network.
Each of the nodes will have a corresponding wallet. Thus we create the wallets first.
I assume that the wallets will be called wallet_01.bin
,
wallet_02.bin
and wallet_03.bin
. Also, I assume that the wallets will be located
in ~/testnet
folder.
Create the ~/testnet
folder and go into it:
mkdir ~/testnet && cd ~/testnet
For the testnet network, I prefer to have fixed addresses for each wallet and no password. The reason is that it is much easier to work with such testnet wallets.
Execute the following commands to create three wallets without password.
For wallet_01.bin:
/opt/monero/monero-wallet-cli --testnet --generate-new-wallet ~/testnet/wallet_01.bin --restore-deterministic-wallet --electrum-seed="sequence atlas unveil summon pebbles tuesday beer rudely snake rockets different fuselage woven tagged bested dented vegan hover rapid fawns obvious muppet randomly seasons randomly" --password "" --log-file ~/testnet/wallet_01.log;
Resulting address and seed:
9wviCeWe2D8XS82k2ovp5EUYLzBt9pYNW2LXUFsZiv8S3Mt21FZ5qQaAroko1enzw3eGr9qC7X1D7Geoo2RrAotYPwq9Gm8
sequence atlas unveil summon pebbles tuesday beer rudely snake rockets different fuselage woven tagged bested dented vegan hover rapid fawns obvious muppet randomly seasons randomly
The command creates a deterministic wallet and exits after its created. The reason for exit is
that monero-wallet-cli
may crash if the blockchain is empty.
The monero-wallet-cli
options are:
- testnet - Used to deploy testnets. The daemon must be launched with --testnet flag.
- generate-new-wallet - Generate new wallet and save it to or .wallet by default.
- restore-deterministic-wallet - Recover wallet using electrum-stylemnemonic.
- electrum-seed - Specify electrum seed for wallet recovery/creation.
- password - Wallet password.
- log-file - Specify log file.
For wallet_02.bin:
/opt/monero/monero-wallet-cli --testnet --generate-new-wallet ~/testnet/wallet_02.bin --restore-deterministic-wallet --electrum-seed="deftly large tirade gumball android leech sidekick opened iguana voice gels focus poaching itches network espionage much jailed vaults winter oatmeal eleven science siren winter" --password "" --log-file ~/testnet/wallet_02.log;
Resulting address and seed:
9wq792k9sxVZiLn66S3Qzv8QfmtcwkdXgM5cWGsXAPxoQeMQ79md51PLPCijvzk1iHbuHi91pws5B7iajTX9KTtJ4bh2tCh
deftly large tirade gumball android leech sidekick opened iguana voice gels focus poaching itches network espionage much jailed vaults winter oatmeal eleven science siren winter
For wallet_03.bin:
/opt/monero/monero-wallet-cli --testnet --generate-new-wallet ~/testnet/wallet_03.bin --restore-deterministic-wallet --electrum-seed="upstairs arsenic adjust emulate karate efficient demonstrate weekday kangaroo yoga huts seventh goes heron sleepless fungal tweezers zigzags maps hedgehog hoax foyer jury knife karate" --password "" --log-file ~/testnet/wallet_03.log;
Resulting address and seed:
A2rgGdM78JEQcxEUsi761WbnJWsFRCwh1PkiGtGnUUcJTGenfCr5WEtdoXezutmPiQMsaM4zJbpdH5PMjkCt7QrXAhV8wDB
upstairs arsenic adjust emulate karate efficient demonstrate weekday kangaroo yoga huts seventh goes heron sleepless fungal tweezers zigzags maps hedgehog hoax foyer jury knife karate
The node will listen for connections at port 28080 and connect to the two other nodes, i.e., those on ports 38080 and 48080. It will store its blockchain in ~/testnet/node_01
.
/opt/monero/monerod --testnet --no-igd --hide-my-port --testnet-data-dir ~/testnet/node_01 --p2p-bind-ip 127.0.0.1 --log-level 0 --add-exclusive-node 127.0.0.1:38080 --add-exclusive-node 127.0.0.1:48080
The monerod
options are:
- testnet - Run on testnet. The wallet must be launched with --testnet flag.
- no-igd - Disable UPnP port mapping.
- hide-my-port - Do not announce yourself as peerlist candidate.
- testnet-data-dir - Specify testnet data directory.
- p2p-bind-ip - Interface for p2p network protocol.
- log-level - Log level.
- add-exclusive-node - Specify list of peers to connect to only. If this option is given the options add-priority-node and seed-node are ignored.
The node will listen for connections at port 38080 and connect to the two other nodes, i.e., those on ports 28080 and 48080. It will store its blockchain in ~/testnet/node_02
.
/opt/monero/monerod --testnet --testnet-p2p-bind-port 38080 --testnet-rpc-bind-port 38081 --zmq-testnet-rpc-bind-port 38082 --no-igd --hide-my-port --log-level 0 --testnet-data-dir ~/testnet/node_02 --p2p-bind-ip 127.0.0.1 --add-exclusive-node 127.0.0.1:28080 --add-exclusive-node 127.0.0.1:48080
Additional monerod
options are:
- testnet-p2p-bind-port - Port for testnet p2p network protocol.
- testnet-rpc-bind-port - Port for testnet RPC server.
The node will listen for connections at port 48080 and connect to the two other nodes, i.e., those on ports 28080 and 38080. It will store its blockchain in ~/testnet/node_03
.
/opt/monero/monerod --testnet --testnet-p2p-bind-port 48080 --testnet-rpc-bind-port 48081 --zmq-testnet-rpc-bind-port 48082 --no-igd --hide-my-port --log-level 0 --testnet-data-dir ~/testnet/node_03 --p2p-bind-ip 127.0.0.1 --add-exclusive-node 127.0.0.1:28080 --add-exclusive-node 127.0.0.1:38080
How you mine is up to you now. You can mine only for the first wallet, and keep other two empty for now, or mine in two nodes, or all three of them.
For example, to mine into two first wallets, the following commands can be used:
in node_01 (mining to the first wallet):
start_mining 9wviCeWe2D8XS82k2ovp5EUYLzBt9pYNW2LXUFsZiv8S3Mt21FZ5qQaAroko1enzw3eGr9qC7X1D7Geoo2RrAotYPwq9Gm8 1
in node_02 (mining to the second wallet):
start_mining 9wq792k9sxVZiLn66S3Qzv8QfmtcwkdXgM5cWGsXAPxoQeMQ79md51PLPCijvzk1iHbuHi91pws5B7iajTX9KTtJ4bh2tCh 1
in node_03 (mining to the first wallet as well):
start_mining 9wviCeWe2D8XS82k2ovp5EUYLzBt9pYNW2LXUFsZiv8S3Mt21FZ5qQaAroko1enzw3eGr9qC7X1D7Geoo2RrAotYPwq9Gm8 1
As can be seen, both node_01 and node_03 mine to the first wallet. The third wallet is not used for mining in this example. The reason is that it will receive xmr, through transfers, from the remaining wallets.
wallet_01:
/opt/monero/monero-wallet-cli --testnet --trusted-daemon --wallet-file ~/testnet/wallet_01.bin --password "" --log-file ~/testnet/wallet_01.log
wallet_02:
/opt/monero/monero-wallet-cli --testnet --daemon-port 38081 --trusted-daemon --wallet-file ~/testnet/wallet_02.bin --password "" --log-file ~/testnet/wallet_02.log
wallet_03:
/opt/monero/monero-wallet-cli --testnet --daemon-port 48081 --trusted-daemon --wallet-file ~/testnet/wallet_03.bin --password "" --log-file ~/testnet/wallet_03.log
The comments used are rather long, so to speed things up, one can make aliases
for them. For example, by adding the following to ~/.bashrc
:
alias testmakewallet1='echo "exit" | /opt/monero/monero-wallet-cli --testnet --generate-new-wallet ~/testnet/wallet_01.bin --restore-deterministic-wallet --electrum-seed="sequence atlas unveil summon pebbles tuesday beer rudely snake rockets different fuselage woven tagged bested dented vegan hover rapid fawns obvious muppet randomly seasons randomly" --password "" --log-file ~/testnet/wallet_01.log; echo ""'
alias testmakewallet2='echo "exit" | /opt/monero/monero-wallet-cli --testnet --generate-new-wallet ~/testnet/wallet_02.bin --restore-deterministic-wallet --electrum-seed="deftly large tirade gumball android leech sidekick opened iguana voice gels focus poaching itches network espionage much jailed vaults winter oatmeal eleven science siren winter" --password "" --log-file ~/testnet/wallet_02.log; echo ""'
alias testmakewallet3='echo "exit" | /opt/monero/monero-wallet-cli --testnet --generate-new-wallet ~/testnet/wallet_03.bin --restore-deterministic-wallet --electrum-seed="upstairs arsenic adjust emulate karate efficient demonstrate weekday kangaroo yoga huts seventh goes heron sleepless fungal tweezers zigzags maps hedgehog hoax foyer jury knife karate" --password "" --log-file ~/testnet/wallet_03.log; echo ""'
# additional alias for making random wallet_04
alias testmakewallet4='{ echo "0"; echo "exit"; } | /opt/monero/monero-wallet-cli --testnet --generate-new-wallet ~/testnet/wallet_04.bin --password "" --log-file ~/testnet/wallet_04.log; echo ""'
alias testmakeallwallets="testmakewallet1; testmakewallet2; testmakewallet3; testmakewallet4"
alias testnode1="/opt/monero/monerod --testnet --no-igd --hide-my-port --testnet-data-dir ~/testnet/node_01 --p2p-bind-ip 127.0.0.1 --log-level 0 --add-exclusive-node 127.0.0.1:38080 --add-exclusive-node 127.0.0.1:48080"
alias testnode2="/opt/monero/monerod --testnet --testnet-p2p-bind-port 38080 --testnet-rpc-bind-port 38081 --no-igd --hide-my-port --log-level 0 --testnet-data-dir ~/testnet/node_02 --p2p-bind-ip 127.0.0.1 --add-exclusive-node 127.0.0.1:28080 --add-exclusive-node 127.0.0.1:48080"
alias testnode3="/opt/monero/monerod --testnet --testnet-p2p-bind-port 48080 --testnet-rpc-bind-port 48081 --no-igd --hide-my-port --log-level 0 --testnet-data-dir ~/testnet/node_03 --p2p-bind-ip 127.0.0.1 --add-exclusive-node 127.0.0.1:28080 --add-exclusive-node 127.0.0.1:38080"
alias teststartwallet1='/opt/monero/monero-wallet-cli --testnet --trusted-daemon --wallet-file ~/testnet/wallet_01.bin --password "" --log-file ~/testnet/wallet_01.log'
alias teststartwallet2='/opt/monero/monero-wallet-cli --testnet --daemon-port 38081 --trusted-daemon --wallet-file ~/testnet/wallet_02.bin --password "" --log-file ~/testnet/wallet_02.log'
alias teststartwallet3='/opt/monero/monero-wallet-cli --testnet --daemon-port 48081 --trusted-daemon --wallet-file ~/testnet/wallet_03.bin --password "" --log-file ~/testnet/wallet_03.log'
alias teststartwallet4='/opt/monero/monero-wallet-cli --testnet --daemon-port 48081 --wallet-file ~/testnet/wallet_04.bin --password "" --log-file ~/testnet/wallet_04.log'
alias testremove="rm -rvf ~/testnet"
alias testremoveandmkdir="rm -rvf ~/testnet; mkdir ~/testnet"
The resulting ~/testnet
folder structure should be as follows:
./testnet/
├── node_01
│ ├── bitmonero.log
│ └── lmdb
│ ├── data.mdb
│ └── lock.mdb
├── node_02
│ ├── bitmonero.log
│ └── lmdb
│ ├── data.mdb
│ └── lock.mdb
├── node_03
│ ├── bitmonero.log
│ └── lmdb
│ ├── data.mdb
│ └── lock.mdb
├── wallet_01.bin
├── wallet_01.bin.address.txt
├── wallet_01.bin.keys
├── wallet_01.log
├── wallet_02.bin
├── wallet_02.bin.address.txt
├── wallet_02.bin.keys
├── wallet_02.log
├── wallet_03.bin
├── wallet_03.bin.address.txt
├── wallet_03.bin.keys
└── wallet_03.log
6 directories, 21 files
Optionally, each node can be started so that it starts mining automatically. With this, there is no need for manually launching the mining operation in each node. It speeds up using using the testnet.
For example, to start the three nodes so that they mine into the first two wallets (like in step 5):
in node_01 (mining to the first wallet):
/opt/monero/monerod --testnet --no-igd --hide-my-port --testnet-data-dir ~/testnet/node_01 --p2p-bind-ip 127.0.0.1 --log-level 1 --add-exclusive-node 127.0.0.1:38080 --add-exclusive-node 127.0.0.1:48080 --start-mining 9wviCeWe2D8XS82k2ovp5EUYLzBt9pYNW2LXUFsZiv8S3Mt21FZ5qQaAroko1enzw3eGr9qC7X1D7Geoo2RrAotYPwq9Gm8 --mining-threads 1
in node_02 (mining to the second wallet):
/opt/monero/monerod --testnet --testnet-p2p-bind-port 38080 --testnet-rpc-bind-port 38081 --no-igd --hide-my-port --log-level 1 --testnet-data-dir ~/testnet/node_02 --p2p-bind-ip 127.0.0.1 --add-exclusive-node 127.0.0.1:28080 --add-exclusive-node 127.0.0.1:48080 --start-mining 9wq792k9sxVZiLn66S3Qzv8QfmtcwkdXgM5cWGsXAPxoQeMQ79md51PLPCijvzk1iHbuHi91pws5B7iajTX9KTtJ4bh2tCh --mining-threads 1
in node_03 (mining to the first wallet as well):
/opt/monero/monerod --testnet --testnet-p2p-bind-port 48080 --testnet-rpc-bind-port 48081 --no-igd --hide-my-port --log-level 1 --testnet-data-dir ~/testnet/node_03 --p2p-bind-ip 127.0.0.1 --add-exclusive-node 127.0.0.1:28080 --add-exclusive-node 127.0.0.1:38080 --start-mining 9wviCeWe2D8XS82k2ovp5EUYLzBt9pYNW2LXUFsZiv8S3Mt21FZ5qQaAroko1enzw3eGr9qC7X1D7Geoo2RrAotYPwq9Gm8 --mining-threads 1
Newly mined blocks require confirmation of 60 blocks, before they can be used. So before you can make any transfers between the wallets, we need to mine at least 60 blocks. Until then, the wallets will have unlocked balance
equal to 0. In contrast, for regular transfers between wallets to be unlocked it takes 6 blocks.
Commands used to start the nodes and wallets: The above image shows the command used for each node (left column) and wallets (right column). Each row represents one node with the corresponding wallet.
After mining first few blocks:
The above image shows the state of the nodes and wallets after first few blocks mined. We see
that the first two wallets already have some xmr, but their unlocked balance
values are zero. For them
to unlock the mined xmr, we need to mine at least 60 blocks.
After mining more than 60 blocks:
After mining more than 60 blocks, the unlocked balance
is no longer zero
and we can start mining transfers between wallets.
Constructive criticism, code and website edits are always good. They can be made through github.