Creating a Testnet Using Geth

With Frontier (finally) launched more and more people are flocking to the development of the Ethereum Distributed Apps or “DAPPs” as we like to call them.

While it’s completly feasible to develop your apps against the Frontier network it is probably safer, and lighter on your wallet, to develop them on your own private network.

Let’s see how we can create our own network to develop on using Geth and a custom genesis file.

First off I am going to assume you already have Geth installed. If not please go to Ethereum.org and follow the instructions to do so.

We need a couple of things in order to succesfully create a private network:

A unique networkid Not allowing outside peers Decreased start difficulty Increased Gaslimit Changing the datadir

Let’s go through these one by one.

A unique networkid

The Frontier network has the simple networkid of ‘1’. Every network has it’s own id. To define that we are working not on the Frontier network but our own private network we can tell geth to use a different networkid by using the --networkid flag. I suggest you pick something high-up to reduce the risk of collision.

Max peers

To exclude the risk of other peers connecting to your private chain further I also recommend you disable peer connections. You can do this by specifing --maxpeers 0 this will prevent Geth from searching for peers on the same networkid.

Start difficulty

The default Genesis block for Frontier expected quite a bit of mining power and as such it set up the difficulty quite high (although in the end it was still way too low as anybody mining of the first day can attest to). This number is so high in fact that the chances of you mining a block successfully are quite slim. You might be waiting ages for fast blocks since the retarget mechanism actually needs to find blocks to scale down the total difficulty and make sure we hit the 15 second block time. To help out with this we can change the difficulty parameter in the genesis file. By lowering the difficulty you will find blocks much faster. I will offer a pre-made genesis file later where this edit is already made.

Increased Gaslimit

Now the last problem is the freeze. The default genesis block has a very low start gasLimit so any contract that you might try to deploy won’t work. You can overcome this by editing the gasLimit key in the genesis file, or again download my pre-made genesis file.

Unique datadir

If you already synced to the Frontier network at one point you already have block data. You want this new network to live in it’s own folder so that you can start this new chain from scratch. You do this by supplying the --datadir flag. I’m using DevChain in the example but feel free to name this anything you want.

All together now

Let’s actually get to work now that you understand the logic behind the requirements.

First off download the development genesis file and place it somewhere you won’t forget about it.

If you want you get edit it and supply your own address with some either by replacing the bbbbbaaaaa82db86a35502193b4c6ee9a76ebe8f address with your own.

Next start geth with the following parameters: ./build/bin/geth --rpc --networkid=39318 --maxpeers=0 --datadir=~/.ethereum/DevChain/ --mine --minerthreads 1 --genesis genesis.json console

If everything went ok you should be finding blocks now… If not, let me know :)