6

I was trying to set-up ethereum private test-net. I was able to create a custom Genesis block and create an account. Now I modified my customGenesis.json to preallocate ethers to my account, I was hit by:

Fatal: failed to write genesis block: wrong genesis block in database (have 6650a0ac6c5e8054, new 423e5a9e61bce67e)

Steps to reproduce:

  1. setup Genesis state:

    geth --identity "Prashant" --fast --cache=1024 --rpc --rpcport "8013" --rpccorsdomain "*" --datadir "myPrivateNetwork2" --port "30312" --rpcapi "db,eth,net,web3,admin,debug,miner,personal,web3" --networkid 1902 --nat "any" init customGenesis.json console

  2. Start geth without init to create account:

    geth --identity "Prashant" --fast --cache=1024 --rpc --rpcport "8013" --rpccorsdomain "*" --datadir "myPrivateNetwork2" --port "30312" --rpcapi "db,eth,net,web3,admin,debug,miner,personal,web3" --networkid 1902 --nat "any" -ipcpath "/home/prsingh/.ethereum/geth.ipc" console

  3. Create an account in geth console

    personal.newAccount("my_password");

  4. Modify customeGenesis.json to preallocate ethers

    "alloc":{
         "0xe43ee2af5a41385ff951f0c3fe2f5156287757a6":
         {"balance": "20000000000000000000" }
     }
    
  5. Again run geth with init

    geth --identity "Prashant" --fast --cache=1024 --rpc --rpcport "8013" --rpccorsdomain "*" --datadir "myPrivateNetwork2" --port "30312" --rpcapi "db,eth,net,web3,admin,debug,miner,personal,web3" --networkid 1902 --nat "any" init customGenesis.json console

At step 5, I am getting the wrong genesis block in database error. I am quite sure this is because I have already run the geth with init param so when I am trying to run it the second time, geth gives error because these in already a genesis block.

But then the question is: How will I pre-allocate ethers to my account?

Here is my customGenesis.json after adding funds to my account.

{
    "nonce": "0x0000000000000042",
    "timestamp": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x00",
    "gasLimit": "0x8000000",
    "difficulty": "0x400",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x3333333333333333333333333333333333333333",
    "config": {
        "chainId": 15,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "alloc":{
    "0xe43ee2af5a41385ff951f0c3fe2f5156287757a6":
    {"balance": "20000000000000000000" }
    }
}
  • I can. But I don't think there is any issue in Genesis file. As I am able to successfully write genesis block the first time. But reinitialising Genesis with some pre-allocated funds gives error. – Prashant Prabhakar Singh Jun 6 '17 at 4:20
  • Run only this command once and then the full command : geth --datadir <path to data directory > init <genesis file path> . Hope it will correct the things. – Aniket Jun 6 '17 at 6:19
  • Is the networkId paramater in geth command and chainId in genesis.json same? – Chalpat Jul 23 '17 at 7:20
  • They both are different ethereum.stackexchange.com/questions/15682/… – Chalpat Jul 23 '17 at 7:27
  • I am trying to fund my account with some ethers and faced the same issue. I tried to execute the steps suggested by Ajay but I am getting Fatal: Failed to write genesis block: database already contains an incompatible genesis block (have 346a147f2301febc, new acdccee41fea8224). – Chalpat Jul 23 '17 at 7:56
6

You cannot do a init again if you have already done a init on datadir. In order to achive what you want you need to first create simply create account .... once account is created use that for pre-funding, by putting it in the genesis file, now go for the init of datadir.

so steps are
1) Creation of account in datadir

geth --datadir <path_of_data_directory> account new ( I have used command line method for account creation, which does not require invocation of geth console)

2) use the account created as pre-funded account, add entry in genesis file.

3) Init of the datadirectory with the genesis file.

geth --datadir <path_of_data_directory> init <path_of_genesis_file>

I have used bare minimum parameters, it should also work fine with the parameter you are using. Main point to note you cannot re-initialize your data directory once it is initialized.

| improve this answer | |
2

It seems that you have specified in the commandline a different networkId that the one in your genesis.json file.

In new version of geth for a private test network you can remove the --networkId parameter if it already in the genesis block.

| improve this answer | |
0

Clear the chaindata folder and then perform the initialization.

| improve this answer | |
  • by doing so, the created account will be lost – Ajay Jun 6 '17 at 15:04
  • Ajay, it wont delete the account if its only chaindata folder – Rafid Sep 2 '19 at 0:39

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