15

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": { }
}
2

5 Answers 5

7

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.

1
  • Thanks Atrophy. I was also facing the same issue and after debugging for 2 days, I found this post and my problem got solved. Apr 19, 2017 at 10:50
16

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": { }

2
0

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
  • 1
    Please open a new post instead posting here
    – Badr Bellaj
    Apr 28, 2017 at 14:22
0

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.

0

I facing the same problem and I solve it by following some rules. Those Rules are "mixhash" = You have to write data 64 times after 0x, "coinbase" =You have to write data 40 times after 0x, "timestamp"= 0x00, "parenthash"=You have to write data 64 times after 0x, "extraData"= "0x00" In this case my json data like:

{
"nonce": "0x000000142",
"difficulty": "0x4000",
"alloc": {
    "6b3fb267ff816af81091946a7e8": {
        "balance": "1000"
    },
    "70604ec24664b629abfa3604fc0140": {
        "balance": "100000"
    }
},
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parenthash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x00",
"gasLimit": "0xfffff"

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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