Skip to content

Instantly share code, notes, and snippets.

@giladoved
Last active December 19, 2023 08:01
Show Gist options
  • Save giladoved/bb62116be3a6d4e5fc02ee3266afc6ce to your computer and use it in GitHub Desktop.
Save giladoved/bb62116be3a6d4e5fc02ee3266afc6ce to your computer and use it in GitHub Desktop.
setup local testnet with geth

Setup a testnet with geth

Create two test accounts

datadir is any location we choose for the testnet to put its data in. Remember the password you enter, 'password' is easy enough. Do this command twice to make two accounts.

geth account new --datadir=/tmp/testnet

Create a custom genesis block

A generic template was taken from: https://github.com/ethereum/go-ethereum/wiki/Private-network

Make sure to fill in the ACCOUNT_ID to initialize our first account with cash. I named the file HelloWorldGenesis.json

{
    "config": {
        "chainId": 15,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "difficulty": "0x400",
    "gasLimit": "0x21000",
    "alloc": {
        "ACCOUNT_ID": { "balance": "0x1500000000000000000000" }
    }
}

Setup our testnet with the custom genesis block

geth --identity "HelloWorldNode" --datadir /tmp/testnet --metrics —-networkid 1999 init HelloWorldGenesis.json

Interact with the testnet

geth --identity "HelloWorldNode" --datadir /tmp/testnet --metrics console

Monitor the data

In another terminal run:

geth monitor --attach /tmp/testnet/geth.ipc system/memory

Links

These links were most helpful for me:

http://ethdocs.org/en/latest/network/test-networks.html

https://medium.com/@WWWillems/how-to-set-up-a-private-ethereum-testnet-blockchain-using-geth-and-homebrew-1106a27e8e1e

@SaintJackson
Copy link

Hi, what will be the consensus to be used when creating the testnet like this? Since I do not see any flag specifying which consensus to use in your demo.

Best,
Jackson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment