I am trying to create a genesis block on my mac for a local ethereum network but I am getting the error:

invalid genesis file: hex string has odd length

when i do it.

My code is the following:

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

The same problem happened to me with geth 1.6, with a genesis file similar to yours.

Last friday geth updated to 1.6 (https://github.com/ethereum/go-ethereum/releases/tag/v1.6.0).

In this release:

Genesis block JSON handling is stricter and safer. Notably, most JSON fields now require the "0x" prefix. (#3794)

I found this documentation page: https://github.com/ethereum/go-ethereum/wiki/Private-network

In this page there is an example of a genesis file that works on geth 1.6.

I think your genesis file works with previous versions.

  • Thanks Atrophy. I was also facing the same issue and after debugging for 2 days, I found this post and my problem got solved. – Dipesh Bhavsar Apr 19 '17 at 10:50

I had the same problem and found that the issue was:

"extraData": "0x0",

If you change it to:

"extraData": "0x00",

The problem goes away.

At this point though you'll have another issue because in the latest version of geth you need a config section. Add the following and you should be good to go.

"config": { }

I was using the same JSON file as above and getting the same "invalid hex" error. Per the suggestion above, I changed to the new JSON file per the link (see below). I can now successfully initialize the chain without getting the hex error. However, I am getting a different error when trying to start a mining node. I am wondering if it's because this includes some pre-funded accounts. Is there syntax available for the genesis JSON above, but with an empty file? (without any pre-funded accounts).

{
    "config": {
        "chainId": 15,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "difficulty": "200000000",
    "gasLimit": "2100000",
    "alloc": {
        "7df9a875a174b3bc565e6424a0050ebc1b2d1d82": { "balance": "300000" },
        "f41c74c9ae680c1aa78f42e5647a62f353b7bdde": { "balance": "400000" }
    }
}
  • 1
    Please open a new post instead posting here – Badr Bellaj Apr 28 '17 at 14:22

As noted in another answer, this appears to be a change with the release of geth 1.6.0.

Since the genesis.json was downloaded instead of generated, I'm not sure if it's appropriate to edit the genesis.json.

I installed geth 1.5.9 and was able to use $ geth init genesis.json with the old format shown in the question.

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.