Introduction
Environment
-
Docker and bottle v0.6.1
-
go v1.10(maybe not required)
-
Node.js v8.11.2
-
Vnt.js && Vnt-kit.js
-
gvnt
You can install them through 'vnt-full-install-guide.md' file.
Say before
This document mainly help developers use VNTChain to start local testnet, develop a DAPP with VNTChain (including create build deploy smart contract and interact with smart contract or VNTChain net).
Why not use official guide directly?
There is long time since it updated last time.Some steps and some way don't work.
I am GenjiLemon.GiitHub:https://github.com/GenjiLemon. Email:lemonfay{AT}qq.com.You have to keep origin URL of this blog if reprint.
Local Start VNTChain
In this section, we will boot local testnet with 2 nodes.One bootnode and one witness node.Most steps are same to official document
Preparation
Firstly, enter the root folder of testnet.
cd ~/project/vntchain/testnet
Create two accounts
-
create first node(node0).
gvnt account new --datadir node0
parameter datadir is for node folder. Here is node0
After that you have to enter password of this account.
Then record the address in the last line.
gvnt account new --datadir node0
INFO [12-23|16:35:46] Maximum peer count VNT=25 LES=0 total=25
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {fbb316db66f6945addf00bc059a3f3dc5c4d8731}
2.create the second node(node1).
gvnt account new --datadir node1
Similar to the node0. Please record the address and password of account node1
3. verify
Use tree command to show the structure of testnet
tree .
├── node0
│ └── keystore
│ └── UTC--2021-12-23T08-36-07.885563339Z--fbb316db66f6945addf00bc059a3f3dc5c4d8731
└── node1
└── keystore
└── UTC--2021-12-23T08-39-59.930865848Z--ea95ebba96a780afe7a59aa5b40af6efd4f95fe9
4 directories, 2 files
You can also get address of account through its file name.
Generate p2p address
Now you are in testnet root folder.
-
Start the console of node0
gvnt --datadir node0 --port 13000 consoleYou can point port of this node after parameter
port.Here is 13000You can see many output lines . Then you will enter console mode.
Welcome to the Gvnt JavaScript console! instance: Gvnt/v0.6.4/linux-amd64/go1.10 INFO [12-23|16:59:08] Coinbase automatically configured address=0xfBb316dB66F6945aDDf00Bc059a3f3dc5c4d8731 coinbase: 0xfbb316db66f6945addf00bc059a3f3dc5c4d8731 at block: 0 (Mon, 01 Jul 2019 00:00:00 CST) datadir: /home/lemon/project/vntchain/testnet/node0 modules: admin:1.0 bp:1.0 core:1.0 debug:1.0 dpos:1.0 net:1.0 personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 vnt:1.0 > -
Get p2p address
Run command in the console.
admin.nodeInfo.vnode
> admin.nodeInfo.vnode
"/ip4/127.0.0.1/tcp/13000/ipfs/1kHmSh19bjN6hV5vLouyxh23HvEBdqFKfQntm1nT4ojzsTu"
Please record the p2p address of node0
Then use ctrl + d to exit the console.You will get many output too.
-
Again with node1
record the p2p address of node1
gvnt --datadir node1 --port 13001 console
admin.nodeInfo.vnode
4. clear temp data
WARNING:
rm -rf node0/gvnt
rm -rf node1/gvnt
5. verify
Use treecommand to see structure.
.
├── node0
│ ├── history
│ ├── keystore
│ │ └── UTC--2021-12-23T08-36-07.885563339Z--fbb316db66f6945addf00bc059a3f3dc5c4d8731
│ └── vntdb
│ ├── 000001.log
│ ├── CURRENT
│ ├── LOCK
│ ├── LOG
│ └── MANIFEST-000000
└── node1
├── history
├── keystore
│ └── UTC--2021-12-23T08-39-59.930865848Z--ea95ebba96a780afe7a59aa5b40af6efd4f95fe9
└── vntdb
├── 000001.log
├── CURRENT
├── LOCK
├── LOG
└── MANIFEST-000000
6 directories, 14 files
Create genesis file
This file helps to init each node in our testnet.
Now you are in testnet root path.
- Create file and enter
touch dpos.json && vi dpos.json
- Paste content template and edit
Sample dpos.json
You can only change witnessesNum , witnessesUrl in config.dpos section and witnesses .
witnessesNum: number of witnesses in testnet
witnessesUrl: list of p2p address of witnesses nodes
witnesses: list of account address of witenesses nodes
Tips:the account address should start with 0x. So you have to add 0x before that you record in section [Create two accounts]
If you want to get Some vnt in the beginning ,please change 'alloc' section.This is for initial account balance.
Here I study from etuereum. Here is link)
{
"config": {
"chainId": 1012,
"dpos": {
"period": 2,
"witnessesNum": 2,
"witnessesUrl": [
"/ip4/127.0.0.1/tcp/13000/ipfs/1kHZgoYyHwFENLb8xQwtodGbtYWb785RhiMhBqo9E782ike",
"/ip4/127.0.0.1/tcp/13001/ipfs/1kHkQLL9xByQVDqubv61K3GjM8k9ntx2XnNu7byWpCNt2YV"
]
}
},
"nonce": "0x0",
"timestamp": "0x5b45b949",
"extraData": "0x",
"gasLimit": "0x47b760",
"difficulty": "0x1",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
"0xfbb316db66f6945addf00bc059a3f3dc5c4d8731": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
},
"0xea95ebba96a780afe7a59aa5b40af6efd4f95fe9": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
}
},
"witnesses": [
"0xfbb316db66f6945addf00bc059a3f3dc5c4d8731",
"0xea95ebba96a780afe7a59aa5b40af6efd4f95fe9"
],
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
-
save and exit
First press ESC and then enter ':wq' and press ENTER
Init Testnet
Now you are in testnet root path and your folder structure looks like this.
tree . . ├── dpos.json ├── node0 │ ├── history │ ├── keystore │ │ └── UTC--2021-12-23T08-36-07.885563339Z--fbb316db66f6945addf00bc059a3f3dc5c4d8731 │ └── vntdb │ ├── 000001.log │ ├── CURRENT │ ├── LOCK │ ├── LOG │ └── MANIFEST-000000 └── node1 ├── history ├── keystore │ └── UTC--2021-12-23T08-39-59.930865848Z--ea95ebba96a780afe7a59aa5b40af6efd4f95fe9 └── vntdb ├── 000001.log ├── CURRENT ├── LOCK ├── LOG └── MANIFEST-000000 6 directories, 15 files-
init node0
gvnt init dpos.json --datadir node0You may get the following output.
INFO [12-24|17:18:55] Maximum peer count VNT=25 LES=0 total=25 INFO [12-24|17:18:55] Allocated cache and file handles database=/home/lemon/project/vntchain/testnet/node0/gvnt/chaindata cache=16 handles=16 INFO [12-24|17:18:55] Writing custom genesis block INFO [12-24|17:18:55] Persisted trie from memory database nodes=9 size=1.44kB time=90.82µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B INFO [12-24|17:18:55] Successfully wrote genesis state database=chaindata hash=276e07…fe0323 INFO [12-24|17:18:55] Allocated cache and file handles database=/home/lemon/project/vntchain/testnet/node0/gvnt/lightchaindata cache=16 handles=16 INFO [12-24|17:18:55] Writing custom genesis block INFO [12-24|17:18:55] Persisted trie from memory database nodes=9 size=1.44kB time=117.686µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B INFO [12-24|17:18:55] Successfully wrote genesis state database=lightchaindata hash=276e07…fe0323If you failed with
Fatal: invalid genesis file: json,please check yourdpos.json.Specially if you get
Fatal: invalid genesis file: json: cannot unmarshal hex string without 0x prefix into Go struct field Genesis.witnesses of type common.Address, please add0xbefore address of accounts. -
init node1
-
gvnt init dpos.json --datadir node1
Similar output to the above.
Boot Testnet
We have to select one node as bootnode.Now we choose node0.
Now you are in testnet root folder.
-
start bootnode
gvnt --networkid 1012 --datadir node0 --port 13000 console
You have to attention paramter datadir and port, if you set others yourself.
Then you will see some output like the following.And You will enter an console environment.
If you want to start with rpc module ,you have to start like this:
gvnt --networkid 1012 --datadir node0 --port 13000 --rpc --rpcapi="db,eth,net,web3,personal,core" --rpcport "8545" --rpcaddr "0.0.0.0" --rpccorsdomain "*" consoleRemember do this when booting local testnet ,if you want to develope DAPP with local testnet rather than Hubble VNT Testnet.
In the sample , your rpc port will be 8545,and you will connect with local through '127.0.0.1:8545'.
Tip:You don't have to start other nodes in this way. Normal is ok.
INFO [12-27|14:14:22] Maximum peer count VNT=25 LES=0 total=25
INFO [12-27|14:14:22] Starting peer-to-peer node instance=Gvnt/v0.6.4/linux-amd64/go1.10
INFO [12-27|14:14:22] Allocated cache and file handles database=/home/lemon/project/vntchain/testnet/node0/gvnt/chaindata cache=768 handles=512
INFO [12-27|14:14:22] Initialised chain configuration config="{ChainID: 1012 Hubble: <nil> Engine: dpos}"
INFO [12-27|14:14:22] Initialising VNT protocol versions="[63 62]" network=1012
INFO [12-27|14:14:22] Loaded most recent local header number=0 hash=276e07…fe0323 td=1
INFO [12-27|14:14:22] Loaded most recent local full block number=0 hash=276e07…fe0323 td=1
INFO [12-27|14:14:22] Loaded most recent local fast block number=0 hash=276e07…fe0323 td=1
INFO [12-27|14:14:22] Regenerated local transaction journal transactions=0 accounts=0
WARN [12-27|14:14:22] There is no witness candidates. If you want to be a witness, please register now.
INFO [12-27|14:14:22] test services kind=*vnt.VNT
INFO [12-27|14:14:22] test services kind=*whisperv6.Whisper
INFO [12-27|14:14:22] ConstructDHT addr=/ip4/127.0.0.1/tcp/13000/ipfs/1kHZgoYyHwFENLb8xQwtodGbtYWb785RhiMhBqo9E782ike
INFO [12-27|14:14:22] started whisper v.6.0
INFO [12-27|14:14:22] IPC endpoint opened url=/home/lemon/project/vntchain/testnet/node0/gvnt.ipc
Welcome to the Gvnt JavaScript console!
instance: Gvnt/v0.6.4/linux-amd64/go1.10
INFO [12-27|14:14:23] Coinbase automatically configured address=0xfBb316dB66F6945aDDf00Bc059a3f3dc5c4d8731
coinbase: 0xfbb316db66f6945addf00bc059a3f3dc5c4d8731
at block: 0 (Wed, 11 Jul 2018 16:01:13 CST)
datadir: /home/lemon/project/vntchain/testnet/node0
modules: admin:1.0 bp:1.0 core:1.0 debug:1.0 dpos:1.0 net:1.0 personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 vnt:1.0
Don't close or stop this terminal.We have to keep it running in the whole testnet life
-
start other nodes.
Now we have only two node, there is only one witeness we have to start.
Start new terminal for each node.
gvnt --networkid 1012 --datadir node1 --port 13001 --vntbootnode "/ip4/127.0.0.1/tcp/13000/ipfs/1kHZgoYyHwFENLb8xQwtodGbtYWb785RhiMhBqo9E782ike" console
You have to change value of --vntbootnode .It is p2paddress of vntbootnode you start in step One.
If you set other folder and port of node, please remember change revelant value.
You will see many output like the following and then enter the console environment.
INFO [12-27|14:21:42] Maximum peer count VNT=25 LES=0 total=25
INFO [12-27|14:21:42] Starting peer-to-peer node instance=Gvnt/v0.6.4/linux-amd64/go1.10
INFO [12-27|14:21:42] Allocated cache and file handles database=/home/lemon/project/vntchain/testnet/node1/gvnt/chaindata cache=768 handles=512
INFO [12-27|14:21:42] Initialised chain configuration config="{ChainID: 1012 Hubble: <nil> Engine: dpos}"
INFO [12-27|14:21:42] Initialising VNT protocol versions="[63 62]" network=1012
INFO [12-27|14:21:42] Loaded most recent local header number=0 hash=276e07…fe0323 td=1
INFO [12-27|14:21:42] Loaded most recent local full block number=0 hash=276e07…fe0323 td=1
INFO [12-27|14:21:42] Loaded most recent local fast block number=0 hash=276e07…fe0323 td=1
INFO [12-27|14:21:42] Loaded local transaction journal transactions=0 dropped=0
INFO [12-27|14:21:42] Regenerated local transaction journal transactions=0 accounts=0
WARN [12-27|14:21:42] There is no witness candidates. If you want to be a witness, please register now.
INFO [12-27|14:21:42] test services kind=*vnt.VNT
INFO [12-27|14:21:42] test services kind=*whisperv6.Whisper
INFO [12-27|14:21:42] ConstructDHT addr=/ip4/127.0.0.1/tcp/13001/ipfs/1kHkQLL9xByQVDqubv61K3GjM8k9ntx2XnNu7byWpCNt2YV
INFO [12-27|14:21:42] started whisper v.6.0
INFO [12-27|14:21:42] IPC endpoint opened url=/home/lemon/project/vntchain/testnet/node1/gvnt.ipc
INFO [12-27|14:21:42] Send message type=0
INFO [12-27|14:21:42] vnt protocol handshake going to send handshake msg to="<peer.ID 1kHZgoYyHwFENLb8xQwtodGbtYWb785RhiMhBqo9E782ike>" ProtocolVersion=62
INFO [12-27|14:21:42] Send message type=0
Meanwhile you will see the bootnode console print some info like:
INFO [12-27|14:21:42] Send message type=0
INFO [12-27|14:21:42] vnt protocol handshake going to send handshake msg to="<peer.ID 1kHkQLL9xByQVDqubv61K3GjM8k9ntx2XnNu7byWpCNt2YV>" ProtocolVersion=62
INFO [12-27|14:21:42] Send message type=0
-
Check status
We now start a testnet which contains 2 witeness node.
We use
admin.peersto check status of other nodes.
Node0 console:
> admin.peers
[{
caps: null,
id: "<peer.ID 1kHkQLL9xByQVDqubv61K3GjM8k9ntx2XnNu7byWpCNt2YV>",
name: "",
network: {
inbound: false,
localAddress: "/ip4/0.0.0.0/tcp/13000",
remoteAddress: "/ip4/192.168.20.176/tcp/13001",
static: false,
trusted: false
},
protocols: null
}]
Node1 console
> admin.peers
[{
caps: null,
id: "<peer.ID 1kHZgoYyHwFENLb8xQwtodGbtYWb785RhiMhBqo9E782ike>",
name: "",
network: {
inbound: false,
localAddress: "/ip4/192.168.20.176/tcp/13001",
remoteAddress: "/ip4/192.168.20.176/tcp/13000",
static: false,
trusted: false
},
protocols: null
}]
-
Start testnet
We have to unlock account of each node .Then start the consensus.
command:
personal.unlockAccount(core.coinbase, "password", 3153600000)The second argument is pssword of your account in this node.
The third argument is time of unlock .In this seconds ,account wil be locked again.
Node0 console:
> personal.unlockAccount(core.coinbase, "password0", 3153600000) true > bp.start()Node1 console
personal.unlockAccount(core.coinbase, "password1", 3153600000)
true
bp.start()
Then there will always be many new output.You can get block number by vnt.core.blockNumber
> vnt.core.blockNumber
318
Maybe every two seconds there will be a new block.
Each time you can only start the net following steps in this section. That is "Boot Testnet" .Or you can make a script for start in the background
Rest of content is in next blog.