Skip to content

Instantly share code, notes, and snippets.

@MJeorrett
Last active March 27, 2023 23:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save MJeorrett/6ef526d12bd0b73b14b42f569fac09c3 to your computer and use it in GitHub Desktop.
Save MJeorrett/6ef526d12bd0b73b14b42f569fac09c3 to your computer and use it in GitHub Desktop.
Private Ethereum network using Clique

DRAFT

Assume working directory of ~/playground/ethereum and that terminal windows are all opened here.

Create account

$ geth --datadir ./node1 account new

You will be prompted to enter and confirm a password. This will create a "keystore" directory in your working directory with the key for the created account saved in it.

Create configuration file

The puppeth tool (parth of ethereum cli) can be used to create a configuration file. Just run the command 'puppeth' without any parameters and complete as follows:

  1. Enter any name you want for the network name, for this example I have entered 'clique_test'
  2. Enter "2" to configure new genesis
  3. Enter "2" to use clique
  4. press enter to take default for block creation target time
  5. Enter the address for the account you created as the sealing account. This is contained in the last part of the name of the file generated by geth (after the '--')
  6. Enter the same address for the account to be prefunded.
  7. leave the deafult for the chain/network id
  8. Add anything you like to embed into the genesis block
  9. Enter "2" to save the existing genesis file and keep the default name (in this case clique_test.json)

Initialise the node

Use geth to initialise the node passing in the data directory and json configuration file.

$ geth --datadir ./node1 init clique_test.json

Start a boot node

This acts as a rendesvous point for your network. Create bootkey and run the node with the following commands:

$ bootnode --genkey=boot.key
$ bootnode --nodekey=boot.key

You should get output something like this:

INFO [08-29|10:59:18] UDP listener up                          self=enode://def597623fd08ac5ef302803f2252920701d945cbe9858aecea13324d5f92d22f17e5c7f506542b84d5d5efec8c6a7c51f55a64ae9d73e12b89390001d4bc5ca@[::]:30301

The node's 'enode' url is reported after "self=". The bit after the '@' symbol needs to be replaced with your publicly visible ip address followed by the port number as shown. E.g: if my publically visible ip address is "87.246.78.46" then my bootnode's enode url is: enode://def597623fd08ac5ef302803f2252920701d945cbe9858aecea13324d5f92d22f17e5c7f506542b84d5d5efec8c6a7c51f55a64ae9d73e12b89390001d4bc5ca@87.246.78.46:30301

Start your mining node

Run

$ geth --datadir ./node1 --bootnodes=<enode_url> --mine --minerthreads=1 --etherbase=<address>  --unlock=<address>

Where enode url is the string sbove and address is the address form the account you created earlier. For example my commands looks something like:

$ geth --datadir ./node1 --bootnodes=enode://def597623fd08ac5ef302803f2252920701d945cbe9858aecea13324d5f92d22f17e5c7f506542b84d5d5efec8c6a7c51f55a64ae9d73e12b89390001d4bc5ca@87.246.78.46:30301 --mine --minerthreads=1 --etherbase=0x8e50708d834f0f7f8d36d4e873e0e10520c80653  --unlock=0x8e50708d834f0f7f8d36d4e873e0e10520c80653
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment