1

I am running a testnet with init property for genesis block i am able to create an account and its working fine only problem is that i am not able to assign any pre ethers to an account which i was able to do in previous implementation of genesis flag while running. Any one can please tell how to do it in this implementation.

Abhishek Ranjan
  • 455
  • 4
  • 12

2 Answers2

2

Yes, put the balance you want for an address in the genesis block. Here's an example:

myGenBlock.json

  {
      "nonce": "0x0000000000000042",
      "difficulty": "0x20000",
      "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "coinbase": "0x0000000000000000000000000000000000000000",
      "timestamp": "0x00",
      "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "extraData": "",
      "gasLimit": "0x2fefd8",
      "alloc": {
        "dbdbdb2cbd23b783741e8d7fcf51e459b497e4a6": {
          "balance": "1606938044258990275541962092341162602522202993782792835301376"
        },
        "e6716f9544a56c530d868e4bfbacb172315bdead": {
          "balance": "1606938044258990275541962092341162602522202993782792835301376"
        },
        "b9c015918bdaba24b4ff057a92a3873d6eb201be": {
          "balance": "1606938044258990275541962092341162602522202993782792835301376"
        },
        "1a26338f0d905e295fccb71fa9ea849ffa12aaf4": {
          "balance": "1606938044258990275541962092341162602522202993782792835301376"
        },
        "2ef47100e0787b915105fd5e3f4ff6752079d5cb": {
          "balance": "1606938044258990275541962092341162602522202993782792835301376"
        },
        "cd2a3d9f938e13cd947ec05abc7fe734df8dd826": {
          "balance": "1606938044258990275541962092341162602522202993782792835301376"
        },
        "6c386a4b26f73c802f34673f7248bb118f97424a": {
          "balance": "1606938044258990275541962092341162602522202993782792835301376"
        },
        "e4157b34ea9615cfbde6b4fda419828124b70c78": {
          "balance": "1606938044258990275541962092341162602522202993782792835301376"
        },
        "0000000000000000000000000000000000000001": {
          "balance": "1"
        },
        "0000000000000000000000000000000000000002": {
          "balance": "1"
        },
        "0000000000000000000000000000000000000003": {
          "balance": "1"
        },
        "0000000000000000000000000000000000000004": {
          "balance": "1"
        }
      }
    }

Assign the balance you want to an address but first make sure you have generated a private key for it otherwise you won't be able to use the balance.

To initialize the private test net run:

mkdir myTestNet
geth --datadir myTestNet init myGenBlock.json

Next whenever you want to use it just point geth to the directory by adding the arguments:

--datadir myTestNet
Sebi
  • 5,294
  • 6
  • 27
  • 52
2

There are two ways for gaining Ether:

  • Pre-allocating through genesis file
  • Mining

Genesis file: This can be done using the alloc field in the genesis file.

  • Create a genesis file first
  • Create accounts using geth --datadir path/to/directory/ account new
  • Allocate ether to this account as mentioned by @Sebi
  • Now start the node using this genesis file (init), --datadir and a unique --networkid

Mining:

  • After starting the node and creating accounts using geth --datadir path/to/directory/ account new or personal.newAccount("<password>").
  • Start mining from this node using miner.start(1) where 1 = no. of mining threads
  • Now, all this mining reward will be allocated to the coinbase account
  • You can then transfer this Ether to other accounts
galahad
  • 3,920
  • 3
  • 26
  • 66