How to load funds/ether into newly created account. I'm using Ganache and Web3js

            var web3 = new Web3("HTTP://localhost:7545");
            var privateAccount = await web3.Personal.NewAccount.SendRequestAsync("ethics subject regret beyond coach grant soft clean sauce identify benefit club");
            var accountsList = await web3.Eth.Accounts.SendRequestAsync();
            var result = await web3.Personal.UnlockAccount.SendRequestAsync(privateAccount, "ethics subject regret beyond coach grant soft clean sauce identify benefit club", 1500000);
            var gas = await web3.Eth.DeployContract.EstimateGasAsync(ABI, byteCode, privateAccount);

            var balance = await web3.Eth.GetBalance.SendRequestAsync(privateAccount);
            var transaction = await web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync(ABI, byteCode, privateAccount, new HexBigInteger(gas.Value));

If you simply create a new account with web3 when the blockchain is running the account's balance will be zero as it's an empty account. If you instead preseed account(s) with a balance upon creating the blockchain you can specify them a desired balance, at least in Ganache.

Here are some instructions for Ganache-CLI, probably something similar works for the non-CLI version: Setting the initial balance of an account in ganache-cli

The main idea is that once the blockchain is created the only way to create Ethers in the blockchain is by mining it - just like in the mainnet. But as you're using a private blockchain you can cheat a bit and add some Ethers into the blockchain upon creation and assign them to the desired accounts.

  • is it possible to add ether into account via web3.js library. Although i didnt find anything in the documentation. Jul 30 '19 at 10:57
  • No I don't think so. Web3 is for interacting with an existing blockchain and existing blockchain has very limited options for gaining Ether Jul 30 '19 at 13:55

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.