Multi-Node Testnet

This document shows how to start a testnet of smartBCH with multiple nodes.

We suggest to use ubuntu 20.04.

Among these nodes, just pick one to generate the genesis file. And all the other nodes do not generate the genesis file, instead, they use the generated genesis file as is.

1. On the nodes which do not generate the genesis file

Step 0: Prepare

Follow the instructions in running a single-node testnet, and just finish the steps 0, 1, 2, 3 and 4 described in it.

Step 1: generate the private keys to operate one validator

cd ~/smart_bch/smartbch
./smartbchd gen-test-keys -n 1 --show-address
2915b09298d0362df490fe3969b10aece94cd3460fb1ba29184cba31516a9b5f 0xF0c6969C2a554ddae639ba1Aa1d2fA11382CAb2B

The above command generates one private key. And the corresponding EOA address is 0xF0c6969C2a554ddae639ba1Aa1d2fA11382CAb2B.

Step 2: generate genesis validator consensus key info

Now we generate the ed25519 private key for consensus engine:

./smartbchd generate-consensus-key-info

The output hex string is consensus pubkey which will be used in generate-genesis-validator command, and a file containing the consensus public and private key is generated under the current directory, named priv_validator_key.json.

Step 3: generate genesis validator info using pubkey generated above

./smartbchd generate-genesis-validator \
--validator-address=0xF0c6969C2a554ddae639ba1Aa1d2fA11382CAb2B \
--consensus-pubkey=a07871d10858179c1bb3c1f0d7bab31103135b76f96b6bd1f06a5bc0d350f862 \
--voting-power=1 \
--staking-coin=0 \

The validator-address is the one we get at step 1, and the consensus-pubkey is the one we get at step 2.

The output hex string contains the information of a validator. Send the this hex string to the node who is genesis-generator.

Step 4: wait for the data directory's tarball and unpack it

The genesis-generator will send you a tarball named dot.smartbchd.tgz, which contains the initial content for the data directory.

cd ~
tar zxvf dot.smartbchd.tgz
rm -rf .smartbchd
./smartbchd init mynode --chain-id 0x2711
cp -rf dot.smartbchd/* .smartbchd/

Step 5: Copy private key file to data directory and start node

Copy priv_validator_key.json generated in Step 2, to the data directory:

cp ./priv_validator_key.json ~/.smartbchd/config/

Now start the node:

ulimit -n 65536
./smartbchd start

Step 6: activate validator

Before you activate your genesis validator, try to get testnet BCH in your validator address, it needs at least

1000000000000000000000 bch

You can ask the genesis-generator to send you some testnet BCH. And you can check your balance with below command (Replace your_validator_address with your genesis validator address):

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["your_validator_address","latest"],"id":1}' -H "Content-Type: application/json" http://localhost:8545

After you have enough bch, you can run the following command:

./smartbchd staking \
--validator-key=07427a59913df1ae8af709f60f536ddba122b0afa8908291471ca58c603a7447 \
--staking-coin=2000000000000000000000000 \
--nonce=0 \

Note: replace the content after --validator-key with your validator private key, and repace the content after --staking-coin with 1000000000000000000000 or even more you have.

⚠️Keep your private key safe, and execute this command on a secure, offline machine

Then broadcast the transaction (replace --your_tx_data with what hex string get above):

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["you_tx_data"],"id":1}' -H "Content-Type: application/json" http://localhost:8545

Now, you had send an editValidator transaction to staking contract. Check this transaction's receipt (replace your_tx_hash with what the hex string you get above):

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["your_tx_hash"],"id":1}' -H "Content-Type: application/json" http://localhost:8545

If the status is 0x1, congratulations, your genesis validator is activated now.

2. On the node which generates the genesis file

Step 0: Prepare

Just finish the steps 0-9 as running a single-node testnet.

Step 1: add genesis validator info to genesis.json using hex strings sent by other nodes

Using ./smartbchd add-genesis-validator multiple times, one time with one hex string sent by one node. Finally you'll include all the validators' information in the genesis.json file.

Then, make a copy of the ~/.smartbchd directory, excluding the node_key.json file.

cp -r ~/.smartbchd ~/dot.smartbchd
rm ~/dot.smartbchd/config/node_key.json

Step 2: start the node

Run the step 10 and 11 as running a single-node testnet.

Step 4: collect seeds information

Collect the p2p seeds information and modify the ~/dot.smartbchd/config/config.toml file.

Step 5: send information to all the other nodes

Make a tarball:

cd ~
tar czvf dot.smartbchd.tgz dot.smartbchd

Then send this dot.smartbchd.tgz file to all the other nodes.