0

Question: How can I get some ether in Ethereum testnet/dev or even private blockchain?

I'm totally confused. If I use a customized genesis block like this:

{
"config": {
    "chainId":123 ,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },

"nonce": "0x0000000000000042",     "timestamp": "0x0",
"parentHash": 
"0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x00",     "gasLimit": "0x8000000",     "difficulty": 
 "0x400",
 "mixhash": 
 "0x0000000000000000000000000000000000000000000000000000000000000000",
 "coinbase": "0x3333333333333333333333333333333333333333",
 "alloc":{"0x17e6672b3a917b7543d44e07846358aaa22a4379":{
 "balance":"8000000000000000000"

 }}

 }

Then if I do

geth --datadir ~/.ethereum_private init ~/CustomGenesis.json 

this error appears:

   Fatal: Failed to write genesis block: database already contains an 
   incompatible genesis block (have 6650a0ac6c5e8054, new 
   644f9b97e5f57df7)

If I leave the "alloc" field empty the error would not show up anymore (but I don't have any ether).

The other option to get some ether is to mine:

 miner.start(1)

But if I do that, null appears. So, I cannot get any ether again.

We don't have this kind of problems when we're using truffle + testrpc. As it allocates ether to all the accounts we create.

So I don't know how I can get some ether in Ethereum testnet/dev or even private blockchain.

1

You cannot change the genesis parameters from already initialized the private blockchain.

You have to reset the blockchain eliminating any previous transaction.

geth --datadir <your_data_directory> removedb

And then you can execute

geth --datadir <your_data_directory> init <your_genesis_file>
1

To create a private blockchain with balance ether.

Save the below code in genesis.json

{
"config": {
    "chainId": 15,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
},
"nonce": "0x0000000000000042",
"difficulty": "0x40",
"gasLimit": "21000000000000000",
"alloc": {
    "0x95490e50a8b43348fa198bad08d4de211fb2b887": { "balance": "100000000000000000000000000" },
    "0xa4f6f95b6cb36025dd09c9f5fe068e401951e963": { "balance": "10000000000000000000" }
}

}

Initialise the node us

geth --datadir "node1" init "/path/to/genesis.json"

Then get into the java console using

geth --datadir "node1" --rpc console

In java console create the coinbase account using

personal.newAccount("Password")

Method 1:

Then start the mining process using

miner.start(1)

Now you can check the balance using

eth.getBalance(eth.accounts[0])

You can able to find the balance

Method 2:

After creating the account copy the account address and close the java console. Then delete the keystore file under node1 folder using

rm -rf `ls | grep -v keystore`

Then replace the account address with the copied one and balances as you wish in the genesis.json file. Then again initialise the node1 using

geth --datadir "node1" init "/path/to/genesis.json"

Connect to the java console and query the balance, now you will have the balance as you mentioned in genesis.json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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