10

Im creating my dapp with following below tutorial. http://www.dappuniversity.com/articles/the-ultimate-ethereum-dapp-tutorial

however Im facing an error when I run

truffle console

it shows

>truffle console

Could not connect to your Ethereum client with the following parameters:
    - host       > 127.0.0.1
    - port       > 7545
    - network_id > *

Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle-config.js)

Truffle v5.0.17 (core: 5.0.16)
Node v10.15.3

I have tried

truffle init

but my command prompt got stacked after it showed

>truffle init

This directory is non-empty...
? Proceed anyway? Yes
- Preparing to download

can anyone please advise me what needed to be changed.

FYI the code inside truffle-config.js is

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*" // Match any network id
    }
  }
};

Thank you

Trey
  • 103
  • 1
  • 1
  • 5

9 Answers9

9

Do truffle develop before doing truffle console

3

My problem was that I was using WSL2 to run my truffle commands and my ganache GUI is in windows. My fix configures WSL2 with the Windows ganache GUI

What I did was

  1. Restart my computer

  2. Specify vEthernet(WSL) as the ganache server enter image description here

  3. Copy the hostname for vEthernet(WSL) into my truffle.config file for the host field

    module.exports = {
      networks: {
        development: {
          host: "192.168.80.1",
          port: 7545,
          network_id: "*"
        }
       }
      }
    

Note: Your host for vEthernet(WSL) might differ from mine and differ each time you restart.

developer
  • 185
  • 7
1

For me the problem was caused by my VPN. I disabled the VPN and immediately worked.

epicrato
  • 111
  • 2
1

In case anyone else runs into this problem. For me it was because I forgot I was using WSL2 so the linux environment wasn't talking to Ganache running on windows.

So instead of wsl terminal, just open up a bash terminal on VSCode, reinstall truffle on windows npm i -g truffle and you should be good to go.

wongx
  • 173
  • 6
0

My project was using port "8545" on my old machine but when I switched to a new machine, Ganache was running on port "7545" and config file was set to be "8545". SO changed the setting in config file.

Yilmaz
  • 1,580
  • 10
  • 24
0

For me the problem was I was running truffle migrate command on windows CMD. And the solution was, I opened a new terminal on VS Code, then typed truffle develop and then I typed truffle migrate and it worked.

Abdulhakim
  • 201
  • 1
  • 6
0

In my case, I was calling the truffle console without starting the Ganache server. Before executing the truffle console. Start your Ganache server.

Praneeth Pj
  • 111
  • 2
0

For those who may stumble across this: I was stuck on this recently - everything seemed to be set correctly but Truffle refused to connect to Ganache (or vice versa). I kept getting the "Could not connect to your Ethereum client" message. On a lark, I tried changing the host address in truffle.js to reflect the computer's actual internal IP address (e.g. 10.10.1.188), and then telling Ganache to run on the Ethernet address instead of loopback. Much to my surprise, it worked immediately. I haven't yet figured out why (firewall rule? codebase issue?).

I realize this is not a best practice because your internal IP will change. But if you're in need of a temporary workaround, this may help.

Anthony
  • 11
  • 2
0

Check that you have Ganache opened

Maruta
  • 131
  • 1
  • 5