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": { }
}
q9f
  • 32,913
  • 47
  • 156
  • 395
tony
  • 165
  • 1
  • 1
  • 6
  • on running which command you are getting this error? – Aniket Apr 18 '17 at 12:35
  • https://dl.dropboxusercontent.com/u/4270001/testnet_genesis.json Link to Ropsten testnet genesis.json file.

    Blog about the change from Morden to Ropsten: https://blog.ethereum.org/2016/11/20/from-morden-to-ropsten/

    – FugueWeb Jun 17 '17 at 06:27

5 Answers5

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

Brad Lucas
  • 161
  • 1
  • 3
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.

Atrophy
  • 86
  • 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. – Dipesh Bhavsar Apr 19 '17 at 10:50
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"

}

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" }
    }
}
Badr Bellaj
  • 18,780
  • 4
  • 58
  • 75
kake
  • 17
  • 1
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.

sealocal
  • 101
  • 2