Build a private chain on local host
In this document we will introduce an easier way to build a private chain on a windows system computer.
Installing Neo node
Install Neo-CLI and make four copies of the node folder with the name of node1, node2, node3, and node4, successively.
For more information refer to Installation of Neo-CLI .
Installing plug-in
Install SimplePolicy to enable the consensus policy. The nodes cannot reach a consensus without the plug-in. For more information, refer to Installing plug-ins .
Creating wallet files
-
Run Neo-CLI and enter the command
create wallet <path>
to create four wallets, for example, 1.json, 2.json, 3.json, and 4.json, with the passwords 1, 2, 3, 4, in sequence. -
Record the onscreen public keys for each wallet, which will be used later.
-
Place each wallet file under each folder of the four nodes.
Modifying config.json
Make the following configurations in config.json of each node:
-
Specify the ports so that each port is not duplicated and is not occupied by other applications.
-
In "UnlockWallet" specify the wallet path and wallet password.
-
Set StartConsensus and IsActive as true.
You can refer to the following example:
node1/config.json
node2/config.json
node3/config.json
node4/config.json
Modifying protocol.json
Configure the following parameters in each node protocol.json. Ensure the configuration in each file is consistent.
-
Magic : The private chain ID, which can be any integer in the range of [0 - 4294967295].
-
StandbyValidators: The public key of the alternate consensus node. Enter the public keys of four wallets.
-
SeedList: The IP address and port number of the seed node. Specify the IP address as
localhost
and the ports as four P2P ports configured before in config.json.
You can refer to the following example:
Creating a shortcut to start
Create a notepad file for ease of starting the private chain. In the file, enter dotnet neo-cli.dll /rpc
, rename it as 1Run.cmd, and then place it under the folder of each node.
At this point the private chain has been set up. All the files we modified are as follows:
Starting the private chain
Enter each node directory and double-click 1Run.cmd
. When the consensus process goes as shown below, the private chain is set up successfully.
The private chain is terminated if you close all the windows.
Withdrawing NEO and GAS
In the genesis block of the NEO network, 100 million NEOs are generated. Additionally, GAS is generated with the generation of new blocks. When the private chain is set up, you can withdraw those NEO and GAS from a multi-party address with Neo-GUI or Neo-CLI, to facilitate your blockchain development and testing.
Withdrawing NEO and GAS using Neo-CLI
Here we want to use a normal node to connect to the private net and withdraw NEO and GAS.
Installing and configuring a normal node
-
Copy any of the consensus node files and name it node0
-
Configure the config.json file:
-
make sure the port is not conflict with the ports of other four nodes.
-
leave the parameters
Path
andPassword
in UnlockWallet blank -
set
StartConsensus
andIsActive
back tofalse
-
-
Copy all the four wallets files created in previous steps into the node0 root directory.
-
Run node0 , open a wallet and enter
show state
to check the node state.When the block height increases and the connected number is not 0, the node is successfully connected.
One of the four consensus nodes must be closed for the normal node to connect to the private net.
Creating multi-party signature addresses
-
Open a wallet from node0
-
Create a multi-signature address using the command
import multisigaddress m pubkeys
:-
m
: the minimal number of signatures needed to complete the transaction -
pubkeys
: the public keys in StandbyValidators in all consensus node wallets.
You must create the multi-party signature address in each wallet so that the transfer transaction can be signed successfully.
-
-
Enter the command
list asset
and you can see 100 million NEO showing up.
Transferring NEO to a normal address
Here we want to send NEO from the contract address to the normal address.
-
Use the command
send <id|alias> <address> <value>
with the normal address of the wallet desired -
Copy the SignatureContext and close the wallet.
-
Open another wallet listed on the multi-signature
-
Use the command
sign <jsonObjectToSign>
with the object copied in step 2 -
Copy the object in Signed Output and close the wallet.
-
Repeat the previous steps the number of times put as minimal. Then you can use
relay <jsonObjectToSign>
and your wallet is ready. -
Use
list asset
to check the wallet balance:
The GAS status becomes available as NEO is transferred. You can use the command show gas
to check the claimable GAS amount. Then you can refer to the preceding steps to withdraw GAS from the multi-party signature address.
Withdrawing NEO and GAS using Neo-GUI
Installing and configuring Neo-GUI
-
Download Neo-GUI from Github and extract the file.
-
Configure the file protocol.json under the Neo-gui folder to connect the client to the private chain:
-
StandbyValidators
:enter the public keys of four wallets created before. -
SeedList
:enter the four virtual machines IP addresses here and leave the port number as it is.
-
-
Configure the file config.json to make sure the Neo-GUI port is not conflict with the ports of other four nodes. If using the same port, Neo-GUI cannot work as Neo-CLI is running.
Start Neo-GUI and open any of the wallets, if you see the connection number in the lower left corner is not 0 and the client has been downloading the blocks, the client has been successfully connected to the private chain.
Creating multi-party signature addresses
From Neo-GUI, open four wallets in turn and do the following:
-
Right-click on the blank area of account page, click
Create Contract Address
->Multi-Signature
. -
Enter the four public keys and set the minimum number of signatures to 3 (the number of consensus nodes/2 + 1). Click
Confirm
. -
Click Wallet -> Rebuild wallet index.
You must create the multi-party signature address in each wallet so that the transfer transaction can be signed successfully .
Now you should see the contract address has 100 million Neo shares.
Transferring NEO to a normal address
Here we want to send the NEO from the contract address to the normal address.
-
From any of the four wallets, click
transaction
->transfer
-
Enter the recipient address and 100 million NEO as the transfer amount
-
The system prompts you that there have not been enough signatures to complete the transaction. Copy the code to your clipboard.
-
Open the second wallet, click
transaction
->signature
and paste the code that you have just copied. -
Click
signature
and copy the code. -
Open the third wallet, click
transaction
->signature
and paste the code that you have just copied. Clicksignature
.At this time you will notice a pop-up window that displays a
broadcast
button in the lower left corner, which means all the signatures required to send the transaction have been collected. -
Click
broadcast
.Once the transfer transaction begins broadcasting it will take a while for successful remittance to the account.
Transferring GAS to a normal address
Open the wallet you want to transfer GAS to and click Advanced
-> Claim GAS
-> Claim
.
GAS has two status, available and unavailable. Once NEO is spent (i.e. transferred out) from the account, the relevant GAS turns to available. Therefore you can transfer GAS to your own account to make them available.
The next operation is similar to the transfer of the NEO. Copy the code that has insufficient signatures, open the second wallet and the third wallet successively to complete transaction signing and broadcasting.
After successful extraction the GAS will enter the first standard address of the wallet (i.e. the top wallet address) where you initiated the extraction of the GAS, as shown.