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

4
  • Check your question please. The error implies that truffle-config.js should state port: 7545, but instead it is stating port: 7574. So I'm guessing that one of these two is not exactly what you say it is. May 15, 2019 at 13:44
  • Sorry typo! still facing same issue after changed to port: 7545
    – Trey
    May 15, 2019 at 14:00
  • 1
    Well have you started an Ethereum node (e.g. Ganache) listening on 127.0.0.1:7545? May 15, 2019 at 14:09
  • Thank you its working now. Shame on me.
    – Trey
    May 15, 2019 at 14:16

9 Answers 9

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.

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.

1

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

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.

0

Check that you have Ganache opened

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.

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.