Ganache-cli: Default account balances are set to 0 after a while

Created on 20 Apr 2018  路  5Comments  路  Source: trufflesuite/ganache-cli

Using ganache-cli via docker (https://hub.docker.com/r/trufflesuite/ganache-cli/) with latest tag and MetaMask 4.2.0 in Firefox Developer Edition from different machines simultaneously, all default account balances are set to 0 after a while (checked by command web3.eth.getBalance(web3.eth.accounts[0]).toNumber() through truffle console).

docker-compose to start ganache:

version: "3"

networks:
  my-network:

services:
  ganache:
    image: trufflesuite/ganache-cli
    restart: always
    container_name: my_ganache
    ports:
      - 8545:8545
    command: -m "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat" -i 4448
    networks:
      - my-network

The same behavior was discovered for https://github.com/harshjv/docker-testrpc

Most helpful comment

It's Internet Wide Ethereum JSON-RPC Attack on port 8545, DONOT listen to inbound queries!

All 5 comments

Same here, it happened after last transaction has been sent about 5 min.
I take a look at block explorer and figure out that all account in ganache-cli send all of eth to one address.
but that address doesn't exist in web3.eth.accounts

It's Internet Wide Ethereum JSON-RPC Attack on port 8545, DONOT listen to inbound queries!

@askysu That's right. Changing mnemonic to private one and locking all created accounts solve the problem.

Hi Vladimir, could you please give more details about it?

@backslash112, first of all generate custom mnemonic using MetaMask or other tool. Then, start ganache-cli using this mnemonic:
ganache-cli -m "<your mnemonic>" -i 4448 -n
Where -n or --secure: Lock available accounts by default (link).
Then, configure your truffle.json file:

const HDWalletProvider = require("./wallet-provider.js");
module.exports = {
    networks: {
        testrpc: {
            provider: () => {
                const testrpcMnemonic = "<your mnemonic>";
                return new HDWalletProvider(testrpcMnemonic, "http://localhost:8545", 0, 10);
            },
            network_id: "*",
            gas: 4700000
        }
}

Where HDWalletProvider is hard copied in local file wallet-provider.js, because there is no actual version in npm. Of course, you can use version of HDWalletProvider from npm, but it is not supported usage of several unlocked accounts in contract deploy scripts (note the last 0 and 10 arguments, 0 - means the first acount index, 10 - means total amount of provided accounts).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leopoldjoy picture leopoldjoy  路  3Comments

dwalintukan picture dwalintukan  路  6Comments

kumavis picture kumavis  路  3Comments

axic picture axic  路  5Comments

Tectract picture Tectract  路  3Comments