Single Node Private Testnet
This document shows how to start a private testnet of smartBCH with only one node.
We suggest to use ubuntu 20.04.

Step 0: install the basic tools.

1
sudo sed -i -e '$a* soft nofile 65536\n* hard nofile 65536' /etc/security/limits.conf ;# enlarge count of open files
2
sudo apt update
3
sudo apt install make cmake g++ gcc git
Copied!
Then download and unpack golang (If you are using ARM Linux, please replace "amd64" with "arm64"):
1
wget https://golang.org/dl/go1.16.5.linux-amd64.tar.gz
2
tar zxvf go1.16.5.linux-amd64.tar.gz
Copied!
And set some environment variables for golang:
1
export GOROOT=~/go
2
export PATH=$PATH:$GOROOT/bin
3
mkdir ~/godata
4
export GOPATH=~/godata
Copied!
After installing golang, we need to patch it for larger cgo stack.
1
wget https://github.com/smartbch/patch-cgo-for-golang/archive/refs/tags/v0.1.1.tar.gz
2
tar zxvf v0.1.1.tar.gz
3
rm v0.1.1.tar.gz
4
cd patch-cgo-for-golang-0.1.1
5
cp *.c $GOROOT/src/runtime/cgo/
Copied!

Step 1: install dependencies

firsrt, install rocksdb dependencies.
1
sudo apt install gcc-8 g++-8
2
sudo apt install libgflags-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev
Copied!
For some unknown reason, on some machines with ubuntu 20.04, the default libsnappy does not work well. So we suggest to build libsnappy from source:
1
mkdir $HOME/build
2
cd $HOME/build
3
wget https://github.com/google/snappy/archive/refs/tags/1.1.8.tar.gz
4
tar zxvf 1.1.8.tar.gz
5
cd snappy-1.1.8
6
mkdir build
7
cd build
8
cmake -DBUILD_SHARED_LIBS=On ../
9
make
10
sudo make install
Copied!
then install rocksdb
1
cd $HOME/build
2
wget https://github.com/facebook/rocksdb/archive/refs/tags/v5.18.4.tar.gz
3
tar zxvf v5.18.4.tar.gz
4
cd rocksdb-5.18.4
5
make CC=gcc-8 CXX=g++-8 shared_lib
Copied!
more infos can refer to rocksdb install doc​
Last, export library path. You should export ROCKSDB_PATH with rocksdb root directory downloaded from above
1
export ROCKSDB_PATH="$HOME/build/rocksdb-5.18.4" ;#this direct to rocksdb root dir
2
export CGO_CFLAGS="-I/$ROCKSDB_PATH/include"
3
export CGO_LDFLAGS="-L/$ROCKSDB_PATH -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd"
4
export LD_LIBRARY_PATH=$ROCKSDB_PATH:/usr/local/lib
Copied!

Step 2: create the smart_bch directory.

1
cd ~ ;# any directory can do. Here we use home directory for example
2
mkdir smart_bch
3
cd smart_bch
Copied!

Step 3: clone the moeingevm repo, and build dynamically linked library.

1
cd ~/smart_bch
2
git clone -b v0.3.1 --depth 1 https://github.com/smartbch/moeingevm
3
cd moeingevm/evmwrap
4
make
5
export EVMWRAP=~/smart_bch/moeingevm/evmwrap/host_bridge/libevmwrap.so
Copied!
After successfully executing the above commands, you'll get a ~/smart_bch/moeingevm/evmwrap/host_bridge/libevmwrap.so file.

Step 4: clone the source code of smartBCH and build the executable of smartbchd.

1
cd ~/smart_bch
2
git clone -b v0.3.3 --depth 1 https://github.com/smartbch/smartbch
3
cd smartbch
4
go build -tags cppbtree github.com/smartbch/smartbch/cmd/smartbchd
Copied!
After successfully executing the above commands, you'll get a ~/smart_bch/smartbch/smartbchd file.

Step 5: generate some private keys only used for test.

1
cd ~/smart_bch/smartbch
2
./smartbchd gen-test-keys -n 10
3
7fc6cf51adb430d9220c9f3ed4e992e75b5d1e8e52fe2bc99183cadc141725bc
4
08c65e04cd27b03d8bb8d19ffadadd82c2dd0935e3f23f313857a2c9629bba43
5
594d82ba88e52b2e037da8513493074eee5e6a6820d836afee5764fb78830285
6
433721d2f0e5c90d0a67a91153eaac3aa9db974ba9b4b9a7be219f02c12c015d
7
ff1f7f7276b877274043a42d17258b79dd4fd32ca17c48a5dc75049c1f931841
8
bab883ae3c7578be66ba5f1c1798dd52ab84ff9403a62c0b478491264df4a50e
9
2698171de1409b229fa14b71fa982507b276c7234c34cee8c42ac0713a614a4f
10
cb7883806fa970ef34b10286b80122b3188b09a24d154d2b81fb30e61c8b99ad
11
e58d53577a8c30b550db1b461c5aee5c8368946be945819cdfdd77dd990e55cd
12
fbb4694007aff7a979f46e76f9ec522015ed74702594864bde419a6c4a24f377
Copied!
The output private keys will be used as input for the next step.
A validator needs two private keys: one ed25519 key for consensus engine (tendermint) and one secp256k1 key for operate it using smart contracts. Now we pick the secp256k1 key out from above generated keys. We just choose the first one and show its corresponding address:
1
ethereum_private_key_to_address 7fc6cf51adb430d9220c9f3ed4e992e75b5d1e8e52fe2bc99183cadc141725bc
2
0xd5Fd2C57069d93B6cE3126275a288D21b8aA2E87
Copied!
If you have not installed the ethereum_private_key_to_address tool, install it as below:
1
sudo apt install npm
2
npm install -g ethereum-private-key-to-address
Copied!

Step 6: initialize the node data using test keys generated above:

1
./smartbchd init mynode --chain-id 0x2711 \
2
--init-balance=1000000000000000000000000000000 \
3
--test-keys="7fc6cf51adb430d9220c9f3ed4e992e75b5d1e8e52fe2bc99183cadc141725bc,\
4
08c65e04cd27b03d8bb8d19ffadadd82c2dd0935e3f23f313857a2c9629bba43,\
5
594d82ba88e52b2e037da8513493074eee5e6a6820d836afee5764fb78830285,\
6
433721d2f0e5c90d0a67a91153eaac3aa9db974ba9b4b9a7be219f02c12c015d,\
7
ff1f7f7276b877274043a42d17258b79dd4fd32ca17c48a5dc75049c1f931841,\
8
bab883ae3c7578be66ba5f1c1798dd52ab84ff9403a62c0b478491264df4a50e,\
9
2698171de1409b229fa14b71fa982507b276c7234c34cee8c42ac0713a614a4f,\
10
cb7883806fa970ef34b10286b80122b3188b09a24d154d2b81fb30e61c8b99ad,\
11
e58d53577a8c30b550db1b461c5aee5c8368946be945819cdfdd77dd990e55cd,\
12
fbb4694007aff7a979f46e76f9ec522015ed74702594864bde419a6c4a24f377"
Copied!
After successfully executing the above commands, you can find the initialized data in the ~/.smartbchd directory. By using the --home option for ./smartbchd command, you can specify another directory. In the ~/.smartbchd directory, the genesis file specifies that all the EOAs corresponding to the above private keys will have a balance of 1000000000000000000000000000000.

Step 7: generate genesis validator consensus key info

Now we generate the ed25519 private key for consensus engine:
1
./smartbchd generate-consensus-key-info | tee generate-consensus-key-info.txt
2
d6569de9567bac00d9946dc72ca71ffe0ff735729eb966e8437d6b6b24fe0ff1
Copied!
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.
Since now we are just running a single node for test, the key file is not so important. In production, a validator's operator must take good care of this key file priv_validator_key.json and back it up safely.

Step 8: generate genesis validator info using pubkey generated above

1
./smartbchd generate-genesis-validator \
2
--validator-address=0xd5Fd2C57069d93B6cE3126275a288D21b8aA2E877 \
3
--consensus-pubkey=d6569de9567bac00d9946dc72ca71ffe0ff735729eb966e8437d6b6b24fe0ff1 \
4
--voting-power=1 \
5
--staking-coin=1000000000000000000000 \
6
--introduction="freeman"
7
7b2241646472657373223a5b3231332c3235332c34342c38372c362c3135372c3134372c3138322c3230362c34392c33382c33392c39302c34302c3134312c33332c3138342c3137302c34362c3133355d2c225075626b6579223a5b3231352c362c3232372c3135392c3232302c37312c39342c36372c3235312c3230352c3139332c3233312c3231352c3232342c3130342c3132342c3232352c37352c36332c3235312c3133352c3139392c3233302c3135372c352c3138372c32362c3234352c32312c3136362c37352c36355d2c22526577617264546f223a5b3231332c3235332c34342c38372c362c3135372c3134372c3138322c3230362c34392c33382c33392c39302c34302c3134312c33332c3138342c3137302c34362c3133355d2c22566f74696e67506f776572223a312c22496e74726f64756374696f6e223a22667265656d616e222c225374616b6564436f696e73223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c352c3130372c3139392c39342c34352c39392c31362c302c305d2c2249735265746972696e67223a66616c73657d
Copied!
The validator-address uses the one we get at step 5, and the consensus-pubkey is the one we get at step 7.
The output hex string contains the information of a validator.

Step 9: add genesis validator info to genesis.json using hex string generated above

1
./smartbchd add-genesis-validator \
2
7b2241646472657373223a5b3231332c3235332c34342c38372c362c3135372c3134372c3138322c3230362c34392c33382c33392c39302c34302c3134312c33332c3138342c3137302c34362c3133355d2c225075626b6579223a5b3231352c362c3232372c3135392c3232302c37312c39342c36372c3235312c3230352c3139332c3233312c3231352c3232342c3130342c3132342c3232352c37352c36332c3235312c3133352c3139392c3233302c3135372c352c3138372c32362c3234352c32312c3136362c37352c36355d2c22526577617264546f223a5b3231332c3235332c34342c38372c362c3135372c3134372c3138322c3230362c34392c33382c33392c39302c34302c3134312c33332c3138342c3137302c34362c3133355d2c22566f74696e67506f776572223a312c22496e74726f64756374696f6e223a22667265656d616e222c225374616b6564436f696e73223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c352c3130372c3139392c39342c34352c39392c31362c302c305d2c2249735265746972696e67223a66616c73657d
Copied!
Using the hex string outputted at the last step as the argument, we call add-genesis-validator. It adds one validator's information into the genesis file. You can use this command repeatedly to add more validators. Since we only need one validator for single node test, here we just use this command once.

Step 10: copy priv_validator_key.json generated in Step 7

1
cp ./priv_validator_key.json ~/.smartbchd/config/
Copied!
Thus, when this node starts up, it can use the private consensus key.

Step 11: start the node:

1
ulimit -n 65536
2
./smartbchd start --unlock="7fc6cf51adb430d9220c9f3ed4e992e75b5d1e8e52fe2bc99183cadc141725bc,\
3
08c65e04cd27b03d8bb8d19ffadadd82c2dd0935e3f23f313857a2c9629bba43,\
4
594d82ba88e52b2e037da8513493074eee5e6a6820d836afee5764fb78830285,\
5
433721d2f0e5c90d0a67a91153eaac3aa9db974ba9b4b9a7be219f02c12c015d,\
6
ff1f7f7276b877274043a42d17258b79dd4fd32ca17c48a5dc75049c1f931841,\
7
bab883ae3c7578be66ba5f1c1798dd52ab84ff9403a62c0b478491264df4a50e,\
8
2698171de1409b229fa14b71fa982507b276c7234c34cee8c42ac0713a614a4f,\
9
cb7883806fa970ef34b10286b80122b3188b09a24d154d2b81fb30e61c8b99ad,\
10
e58d53577a8c30b550db1b461c5aee5c8368946be945819cdfdd77dd990e55cd,\
11
fbb4694007aff7a979f46e76f9ec522015ed74702594864bde419a6c4a24f377"
Copied!
You can also ignore the unlock argument to unlock no accounts.
This command starts the node which provides JSON-RPC service at localhost:8584. You can use the --http.addr option to select another port other than localhost:8584. We unlocked accounts created at genesis, which can be shown using the following command:
You can also use --mainnet-url option to specify a bitcoincashnode's RPC endpoint, and use --home option to specifiy another data directory other than ~/.smartbchd .
1
# Run this command in another terminal:
2
curl -X POST --data '{"jsonrpc":"2.0", "method":"eth_accounts", "params":[],"id":1}' \
3
-H "Content-Type: application/json" http://localhost:8545 | jq
Copied!
And you can see something like:
1
{
2
"jsonrpc": "2.0",
3
"id": 1,
4
"result": [
5
"0x876367b14fe2c725ed4bfc4ace406ea53db58d0f",
6
"0x8c1fe0ad5e59d72ffd064ff80e0c605530af8806",
7
"0xa321e9ca672fb04b3c57160f93a40b70fb3f1d6b",
8
"0xa6f8d15b18b2b93cbf7fae192184ccd9e03bfaf4",
9
"0xb77f11af5206fdfd87011744ea1c0b3bf77ca4ec",
10
"0xc38a47a2481bc692c2203e7e7e5e73c474bea43c",
11
"0xd5fd2c57069d93b6ce3126275a288d21b8aa2e87",
12
"0xdc7c3b6c76eed26bf224a9f1a300b79ce8bc68b2",
13
"0xf995503a428d2deaeb53075dc0476affeee95f05",
14
"0xfb2c39aafd37c6d17e16b73cc8601f77ed5586b9"
15
]
16
}
Copied!
You can find the documents for RPC here.
Last modified 26d ago