trufflesuite / ganache-cli-archive

Fast Ethereum RPC client for testing and development. See https://github.com/trufflesuite/ganache for current development.
https://www.trufflesuite.com/ganache
MIT License
3.36k stars 695 forks source link

Default account balances are set to 0 after a while #512

Closed zatsepinvl closed 6 years ago

zatsepinvl commented 6 years ago

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

trsmarc commented 6 years ago

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

askyme commented 6 years ago

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

zatsepinvl commented 6 years ago

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

backslash112 commented 6 years ago

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

zatsepinvl commented 6 years ago

@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).