9

I'm trying to set up a private chain with geth using --dev that has several accounts with lots of ether. It seems unclear if this is possible anymore according to this.

Here's what I tried on geth 1.4.x and 1.5:

geth --datadir data --dev --password <(echo -n foobar) account new
geth --datadir data --dev --password <(echo -n foobar) account new
geth --datadir data --dev --password <(echo -n foobar) account new

Then init like so:

geth --datadir data --dev --password <(echo -n foobar) init custom.json

Then running geth with mine:

geth --datadir data --dev --password <(echo -n foobar) \
  --unlock 0,1,2 \
  --verbosity 6 \
  --rpc --rpcaddr "0.0.0.0" --rpccorsdomain '"*"' --nodiscover \
  --rpcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" \
  --mine --minerthreads 1 --gasprice 0

Then I use curl to check the balance of the accounts. Result is 0x0.

If I remove the --dev option there is balance, but it takes forever as it then uses the real DAG. I don't want that as this if for testing.

How to best get multiple preallocated accounts with lots of ether for a private dev chain?

Thanks!

8

2 Answers 2

2

It is suppossed to be done by editing your custom genesis file of your testnet. adding something like:

//The genesis file
"alloc":{
        "address":{
                  "balance": "1000000"
                  }
        }
}

Source: https://souptacular.gitbooks.io/ethereum-tutorials-and-tips-by-hudson/content/private-chain.html

6
  • This does not work anymore for dev...hence my question.
    – murrekatt
    Sep 29, 2016 at 20:52
  • Ok, if i find any other solution for this, i'll tell you.
    – KanekiDev
    Sep 30, 2016 at 6:44
  • Tried a bit ago and it worked for me. Check that you are starting the testnet properly with your custom genesis file.
    – KanekiDev
    Sep 30, 2016 at 7:41
  • I don't use testnet... --dev and private chain
    – murrekatt
    Oct 3, 2016 at 13:00
  • 1
    using --dev causes your private to start with a preconfigured set of options. So no chance to preallocate as you are not using a custom Genesis.json file but a preconfigured one.
    – KanekiDev
    Oct 4, 2016 at 7:08
1

I did it like this:

  1. Initialise geth in dev mode with the -- flag

    geth --dev --allow-insecure-unlock

    Never do this in mainnet mode.

  2. Attach a web3 js console

  3. Run this to create 10 unlocked accounts and fund them from the default account:

    for (i=0;i<10;i++){ a = personal.newAccount('pwd') personal.unlockAccount(a,'pwd',0) web3.eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[i+1],value:1000000000000}) }

Your Answer

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

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