0

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));
Majd TL
  • 3,217
  • 3
  • 17
  • 36

1 Answers1

1

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.

Lauri Peltonen
  • 29,391
  • 3
  • 20
  • 57