8

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" }
    }
}
Prashant Prabhakar Singh
  • 8,026
  • 5
  • 40
  • 79
  • 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 06 '17 at 04: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 06 '17 at 06:19
  • Is the networkId paramater in geth command and chainId in genesis.json same? – Chalpat Jul 23 '17 at 07:20
  • They both are different https://ethereum.stackexchange.com/questions/15682/the-meaning-specification-of-config-in-genesis-json – Chalpat Jul 23 '17 at 07: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 07:56
  • Hi there. If you have a new question, please ask it by clicking the Ask Question button, rather than adding it as an answer to an existing question. – Richard Horrocks Jul 23 '17 at 09:18
  • This is a question and should be posted as a new question. Not in the answer field. – Omkar Khair Jul 23 '17 at 09:31
  • @Chalpat The error basically means that you already have a genesis block. So if you are following my steps, I was calling init customGenesis.json twice. But in steps suggested by Ajay, you call this only once and hence do not try to override pre-existing genesis block. You must have already called init and hene getting this error. Give it a fresh start. – Prashant Prabhakar Singh Jul 24 '17 at 05:37

4 Answers4

8

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.

Ajay
  • 499
  • 3
  • 13
3

Clear the chaindata folder and then perform the initialization.

anonymous
  • 351
  • 3
  • 13
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.

Ismael
  • 30,570
  • 21
  • 53
  • 96
1

If you're failing to get Ropsten test net to load from your custom ethereum location using something like this:

geth --ropsten --syncmode fast --datadir /mnt/foo/.ethereum

Try changing the datadir to actually point at the ropsten data, which is one folder deeper in .ethereum.

geth --ropsten --syncmode fast --datadir /mnt/foo/.ethereum/ropsten
forgetso
  • 163
  • 6