ethereumtrufflegeth

How to get some ether in my local Geth account?


I have set up Geth and created some account with no balance in them. So I cannot make any transaction as it costs Gas fee. How to create account with some initial balance so that I can test my contracts. I have created account using the following command:

    > personal.newAccount()

Solution

  • Assuming that you're running a private network and not connecting to an already existing public network (e.g. Ropsten, Rinkeby, Kovan, ...).

    You can add the pre-funded accounts to your genesis.json, under the alloc property. Example from the linked documentation:

    "alloc": {
        "7df9a875a174b3bc565e6424a0050ebc1b2d1d82": { "balance": "300000" },
        "f41c74c9ae680c1aa78f42e5647a62f353b7bdde": { "balance": "400000" }
    }
    

    These accounts will be funded in the first block, so you'll need to re-init your network in order to fund the accounts.


    If you want to fund your accounts on a public network, you can't just re-init the whole public network. But there are so called faucets for testnet networks, that give you some small amount of testnet ETH. Example: https://faucet.metamask.io/ (requires MetaMask wallet extension to be installed in your browser).