1

I want to setup a private testnet. I followed the guide in:

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

With the following CustomGenesis.json:

{
    "nonce": "0x0000000000000042",     "timestamp": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x0",     "gasLimit": "0x8000000",     "difficulty": "0x400",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x3333333333333333333333333333333333333333",     "alloc": {     }
}

If I run the command

geth --identity "MyNodeName" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir "C:\chains\TestChain1" --port "30303" --nodiscover --rpcapi "db,eth,net,web3" --networkid 1999 init /path/to/CustomGenesis.json

with my specific information I get the follwoing error message:

Fatal: invalid genesis file: hex string has odd length

What am I doing wrong?

1

remove the spaces from your file make each option per line like the following example

{
    "nonce": "0x0000000000000042", 
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", 
    "difficulty": "0x400", 
    "alloc": {},
    "coinbase": "0x0000000000000000000000000000000000000000", 
    "timestamp": "0x00", 
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 
    "extraData": "test Ethereum Genesis Block", 
    "gasLimit": "0xffffffff",
     "alloc": {  }
}
  • This isn't working for me where extraData is "0x0". This was not a problem for me in the past, something to do with updates to geth? – Samuel Barnes May 18 '17 at 18:37
  • Doesn't work for me either – fccoelho Jun 27 '17 at 12:28
1

There is nothing wrong with the genesis file that you're having. It's just that they have updated the genesis file structure to include some more parameters in its config section. Here is the Source.

I hacked my way into creating the genesis file like below.[this is new genesis file]

{
    "config": {
    "chainId": 123,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "nonce": "0x0000000000000045",
    "timestamp": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "gasLimit": "0x8900000",
    "difficulty": "0x400",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0xbe8d5fce9f60ab06b527dd177eed96eb95ee4138",
    "alloc": {
        "0xbe8d5fce9f60ab06b527dd177eed96eb95ee4138" : {"balance" : "10000000000000000000"} 
    }

}

This is my old genesis file with which I was trying to run the private chain, but it was giving me same issue. You shall notice the difference in the config section of the json file.

{
    "nonce": "0x0000000000000045",
    "timestamp": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x0",
    "gasLimit": "0x8100000",
    "difficulty": "0x400",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0xb31539d9474f5643644f52f475b16913ec169cc3",
    "alloc": {
        "b31539d9474f5643644f52f475b16913ec169cc3" : {"balance" : "10000000000000000000"} 
    },
    "config": {
  "homesteadBlock": 0
}
}

Also, I removed the extradata parameter. It was giving issue to me.

So in summary.

  1. update the config object in json file.

  2. removed the extradata field.

then, I was able to run the private eth chain locally.

$ geth --datadir datadir1/ --networkid 123 --verbosity 6  init genesis1.json 
DEBUG[08-13|18:01:21] Reloaded keystore contents               accounts=1
TRACE[08-13|18:01:21] Started watching keystore folder         path=`<your/path>`/chain1/datadir1/keystore
INFO [08-13|18:01:21] Allocated cache and file handles         database=`<your/path>`/chain1/datadir1/geth/chaindata cache=128 handles=1024
DEBUG[08-13|18:01:21] Reloaded keystore contents               accounts=1
INFO [08-13|18:01:21] Writing custom genesis block 
INFO [08-13|18:01:21] Successfully wrote genesis state         hash=661ab5…56d3c4

Try it and let me know whether the problem persists. Cheers!

  • Thanks, that also worked for me. Correct answer for the moment until something changes. – teclis Oct 6 '18 at 17:59
1

A couple of problems with the config from http://ethdocs.org/en/latest/network/test-networks.html#test-networks when using Geth 1.8 ...

  • The hex strings have to have an even number of digits, even 0. So timestamp and extraData need to be "0x00" rather than "0x0". (Oddly the hex string "0x400" appears to be accepted, I didn't dig into that).
  • You need the new "config" structure as outlined in the previous answer.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.