Setting up a private NEO chain, step-by-step

The steps are the following: Docker setup → neo-privatenet-docker → neo-python → connect to the private net and create a wallet → claim the initial 100,000,000 NEO.

Docker Setup

Make sure you have Docker installed and running:

https://docs.docker.com/engine/installation/#desktop

https://docs.docker.com/engine/installation/#desktop Make sure Docker is updated to the latest version

You should be able to run $ docker ps without getting an error

Run the private chain Docker container

Clone neo-privatenet-docker, then build and run the Docker container with the four initial consensus nodes:



$ cd neo-privatenet-docker

$ ./docker_build.sh

$ ./docker_run_and_create_wallet.sh $ git clone https://github.com/CityOfZion/neo-privatenet-docker.git $ cd neo-privatenet-docker$ ./docker_build.sh$ ./docker_run_and_create_wallet.sh

This will take a while. It creates a new Docker image with 4 consensus nodes, creates a wallet, transfers the initial 100m NEO to this wallet (by creating a transaction signed by 3 of the 4 consensus nodes, and waits for the blockchain to confirm the transaction), waits a moment and finally claims an initial amount of 40 GAS. The final output looks similar to this:

All done!

- WIF key: L1nqvvVGGesAQ5vLyyR21Q2gVt4ifw8ZrKGJa58tv9xP7hGa2SMx

- Wallet file: /tmp/wallet

- Wallet pwd: coz

Shutting down. This may take a bit... Copying wallet file and wif key out of Docker container... -------------------- All done! You now have 2 files in the current directory: neo-privnet.wallet .. a wallet you can use with neo-python (pwd: coz)

neo-privnet.wif ..... a wif private key you can import into other clients Enjoy!

At this point, the Docker container running the consensus nodes is running in the background. You can see it with $ docker ps :

$ docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

6f7ed0d4ae3a neo-privnet "/bin/bash /opt/pr..." 2 hours ago Up 2 hours 0.0.0.0:20333-20336->20333-20336/tcp neo-privnet

If you encounter an error like Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: unauthorized: incorrect username or password , you may need to login to Docker hub $ docker login with your user-id (not email).

, you may need to login to Docker hub with your user-id (not email). When the Docker container stops or restarts, all state is deleted (the whole ‘old’ blockchain will be gone), and you should also remove Chains/privnet from neo-python and any privnet wallets you created.

neo-python

Now we can connect to the private network with neo-python, and either use the wallet that is produced in the step above, or import the WIF key into a custom wallet.

Setup neo-pytho as described in the README: https://github.com/CityOfZion/neo-python#getting-started

as described in the README: https://github.com/CityOfZion/neo-python#getting-started Connect with neo-python to the private chain:

$ python prompt.py -p

NEO cli. Type 'help' to get started neo>

The number of blocks should be increasing continuously (eg. ‘Progress 0/1’)

Open the wallet:

neo> open wallet neo-privnet.wallet

password> coz

neo> wallet rebuild

At this point, you have 100m NEO in your wallet and you can do as you please. Check the balance with neo-python :

neo> wallet

Script hash b'i\xd5r\xef\\\xf2=\xb32\xb7\xffe\xa4\t@6\xdbM\x1b\xb7' <class 'bytes'>

Wallet {

"percent_synced": 100,

"path": "privnet",

"addresses": [

{

"votes": [],

"balances": {

"c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b": "100000000.0"

},

"version": 0,

"is_watch_only": false,

"frozen": false,

"script_hash": "ARRUJLMrTipDfvzUGHNJ3qAAcQRSdtUcEX"

}

],

"public_keys": [

{

"Public Key": "02c017615119d81f4b3ab7ddb016e22e3313cacb6ab5cf2ef38addd752ac1b3d9f",

"Address": "ARRUJLMrTipDfvzUGHNJ3qAAcQRSdtUcEX"

}

],

"synced_balances": [

"[NEO]: 100000000.0 "

],

"height": 402

}

At this point you now have a private NEO chain up and running and full control over the initial funds. Happy hacking!

How to restart and reset the private network

The Docker container does not persist any state. If it stops or restarts, all state is lost and the whole blockchain will be newly created at the next start.

It’s important to remove the old chain files from neo-python ( Chains/privnet ), else you’ll run into problems running the old database against another chain.

neo-python$ rm -rf Chains/privnet/

You can manually restart the private-net container by running ./docker_run.sh . This stops the neo-privnet container if it is running, and starts a fresh one:

$ ./docker_run.sh

Stopping container named neo-privnet

Removing container named neo-privnet

Starting container...

7e23e2fe1475489503f4d6b6a619275d806043dbeb0672e981ec3938c875167f

Claiming the initial GAS

neo-python does not yet support claiming GAS. You can claim it with the official NEO tools as described in the NEO private chain docs beginning with step 5.

Docker Tips & Tricks

Here are a few often-used Docker commands:

docker ps lists all running instances, docker ps -a also all stopped ones - docs

lists all running instances, also all stopped ones - docs docker images lists all your local images from which a container can start from - docs

lists all your local images from which a container can start from - docs docker exec -it {container-id} /bin/bash opens a bash interface into the running container - docs

opens a bash interface into the running container - docs docker stop {container-id} stops the container - docs

stops the container - docs docker rm -f {container-id} stops and deletes the container - docs

stops and deletes the container - docs docker run to start a new container - docs

NEO TestNet

The NEO project also provides a running TestNet, but this should be only used in the final stages of development (for a variety of reasons).