[Ethereum] How to i reset ether balances in truffle

testrpctruffle

If you use truffle for a while, you gradually deplete all your ether from the default account. Now truffle is defunct. How do I top-up the ether?

Note I think truffle uses testrpc in the default when you run truffle test or truffle develop. But I don't know how to take advantage of this, and can't find where testrpc is installed.

Clarifications added after initial post:

Truffle starts testrpc internally when you run truffle test, so I can't provide parameters to testrpc. Truffle/testrpc save the ether balances from run to run, so that the ether balance for accounts[0] is continuously depleted over time. I have been constantly replenishing the ethers in accounts[0] by transferring ether manually from higher numbered accounts in the truffle develop console. Also, I can't find where testrpc is installed so I can't run it manually. Additionally, I can't figure out how truffle runs testrpc, though I have looked in the truffle executable file (/usr/local/bin/truffle on my computer).

Solution:

Turns out my problem was I had an instance of truffle develop running in another tab. That is why the ether balances were continuously depleting. Oops!

Best Answer

I cannot answer how to replenish after the local blockchain is already running, but it is possible to start your accounts with (much) more ether.

Firstly, testrpc has now been replaced by ganache-cli, which is just the same. It stands for ganache command line as there is also a gui available. As you said, when you run commands such as truffle test, the default setup of ganache-cli is launched. Therefore to add options you have to first start your custom ganache. Assuming you have Node.js installed just run the following to install ganache-cli:

npm install -g ganache-cli

Then to start ganache with, for example, 10'000 ether on each of the 10 addresses run:

ganache-cli --defaultBalanceEther 10000

Now when you run truffle test, it will be on this local blockchain and you should have enough to work with.

Refer to the following link for more options such as number of accounts or gas price: ganache-cli doc