How to run a private network of the NEO blockchain

Chris Hager
Nov 6, 2017 · 8 min read

Running a private network of the NEO blockchain is an integral part of working with the blockchain, in particular for writing and testing dApps and smart contracts. A private network is a complete NEO blockchain for yourself, isolated from the public networks. You can spin it up quickly, claim the initial 100 million NEO, and experiment with all aspects of it.

This post is a step-by-step guide on setting up a private chain with Docker and Python on Mac, Linux and Windows, and an introduction to neo-python and neo-privatenet-docker.

Update 2017–11–20: There is now a turnkey Docker image with a pre-build private network and a wallet with 100m NEO and 16.6k GAS available here: https://hub.docker.com/r/cityofzion/neo-privatenet/. If you are unsure what to use, use this ready-to-go image instead of building it yourself! You can even easily run it with neoscan.

Note for Windows users: You’ll need to use the Linux subsystem because LevelDB does not easily work natively on Windows.

NEO itself and the native tooling is primarily developed with C# using Windows. The official NEO documentation on private chains gives a good overview how to setup a private network with a Windows toolchain and 4 Windows virtual machines as consensus nodes.

Thanks to the monumental efforts of the City of Zion community (CoZ), running a private chain is possible on any platform with Docker and Python, with minimal system requirements. The two specific projects we are going to use are neo-python and neo-privatenet-docker:

  • neo-python — allows us to run a full NEO node and to interact with the blockchain with Python 3.
  • neo-privatenet-docker — allows us to run a whole NEO blockchain with 4 consensus nodes in a single, lightweight Docker container

At this point I also want to mention neo-js, a NEO node implementation in JavaScript, with several features in the pipeline. neo-js is not quite as mature as neo-python, but already supports all RPC calls, and you can run a full local node, saving the blockchain data into a MongoDB database.

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

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

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

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:

  • At this point, the Docker container running the consensus nodes is running in the background. You can see it with $ docker ps:
  • 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).
  • 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.

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.

  • The number of blocks should be increasing continuously (eg. ‘Progress 0/1’)
  • Open the wallet:
  • At this point, you have 100m NEO in your wallet and you can do as you please. Check the balance with neo-python:

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

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.

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:

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.

Here are a few often-used Docker commands:

  • docker ps lists all running instances, docker ps -a also all stopped ones - docs
  • docker images 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
  • docker stop {container-id} stops the container - docs
  • docker rm -f {container-id} stops and deletes the container - docs
  • docker run to start a new container - docs

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).

neo-python

neo-python is an amazing project, a community effort to re-implement the original C# NEO project in Python! It has come a long way and already supports the following functionality:

  • Running a Python based NEO P2P node
  • Interactive CLI for configuring node as well as inspecting and interacting with the blockchain
  • Executing smart contracts on the blockchain in a Python virtual machine
  • Very basic Wallet functionality (not fully tested, please do not use on mainnet)

neo-python has been forked from a “very” preliminary Python SDK, but development really started in July 2017, with constant contributions since then:

As of November 3, 2017, neo-python has 18 contributors, and is spearheaded by localhuman.

If you want to work with the NEO blockchain on a platform other than Windows, you’ll most certainly interact with neo-python in one way or the other. It’s an integral part of the cross-platform development toolchain, actively developed, and just overall a great project.

I just want to send a big thank-you to all the individuals who contributed to making this possible! ♥️ I’m excited about the bright future of this project and it’s further development.

neo-privatenet-docker

Let’s take a closer look at neo-privatenet-docker, which allows us to easily run a private NEO blockchain within an Ubuntu Docker image. A private chain requires at least 4 consensus nodes, which are all running inside this single Docker container. The main contributors are hal0x2328 and phetter.

Let’s start with the Dockerfile:

  • The image is based on Ubuntu 16:04
  • Various system utilities are installed, including LevelDB, a fast key-value storage from Google, and sqlite3, a self-contained, serverless, zero-configuration, transactional SQL database engine.
  • The Microsoft apt repositories are setup, and the dotnet-sdk-2.0.0 is installed. Remember, the original NEO project is implemented in C# and runs on .NET Core.
  • The the neo-cli Ubuntu release is downloaded

That’s pretty much the whole setup. After this, neo-cli is extracted 4 times (once for each consensus node), and the private chain startup files are copied:

When you run the Docker container with docker_run.sh, it starts the container with 4 open ports (20333-20336, mapped to the host), and invokes the private_chain_start.sh script:

private_chain_start.sh in turn starts 4 NEO nodes by executing start_cli.sh four times:

This code sets a few variables from the arguments (dnpath, wallet, password), runs dotnet neo-cli.dll, opens the initial node wallet and calls start consensus in order for the nodes to start working. At this point, blocks in the private chain are being created.

That’s pretty much it! And even though it doesn’t look like much code, it’s a life-saver for getting started with NEO blockchain development and running a private chain, because it makes it just so easy and accessible. Again a big thank-you to the developers driving this project!

I would suggest that you try it out right now! Just follow the getting started guide above and you will have your own private NEO chain running in no time.

Feel free to join the NEO Slack and say hi, it’s an open and welcoming community! You can also find links to various other resources on the official NEO homepage at neo.org.

If you have feedback or comments regarding this post, please reach out to the author via @metachris.

Proof of Working

COZ community magazine

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store