0

Although it compiles successfully

truffle migrate --network ganache gives the following error:

Unknown network "ganache". See your Truffle configuration file for available networks.

I believe I have it wired correctly

Truffle v5.1.34 (core: 5.1.34) Node v12.18.0

Code sample:

const path = require("path");
require("dotenv").config({path: "./.env"});
const HDWalletProvider = require("@truffle/hdwallet-provider");
const MetaMaskAccountIndex = 0;

module.exports = { // See <http://truffleframework.com/docs/advanced/configuration> // to customize your Truffle configuration! contracts_build_directory: path.join(__dirname, "client/src/contracts"),

networks: { development: { port: 7545, host: "127.0.0.1", network_id: "*" } }, ganache: { provider: function() { return new HDWalletProvider(process.env.MNEMONIC, "http://127.0.0.1:7545", MetaMaskAccountIndex)

},
network_id: 5777

}, compilers: { solc: { version: "0.6.1" } } };

I believe I have it wired in my truffle-config.js file correctly. Any idea why this is going on?

  • 1
    The screenshot actually says "compiled successfully", and the error which appears after that line is a runtime error. So to begin with, the title of your question is wrong. – goodvibration Jul 07 '20 at 20:13
  • Speaking of screenshots, please don't use them in your question. It is impossible to copy/paste from them in order to refer to your question or reproduce the problem. Use plain text only (no links either). Also, encapsulate any code that you post in your question with at the beginning and at the end. – goodvibration Jul 07 '20 at 20:14
  • @goodvibration I have made above changes and although I am thrilled to see I overlooked that it actually compiled. I am at a loss on how to get beyond this runtime error. – CloudTech Support Jul 07 '20 at 20:28
  • Invalid JSON RPC response: "" is typically because there is no active node (Ganache, Geth, Parity, etc), which is listening on the port that your application (Truffle in this case) is configured to work with. – goodvibration Jul 07 '20 at 20:46
  • @CloudTechSupport It appears you have an extra space in the provider URL "http://127.0.0.1: 7545", just before the port number. Another thing to check is ganache is running on that port, 8545 is also popular for that. – Ismael Jul 08 '20 at 20:59
  • @ismael I fixed the space there however it seems truffle is still unable to find the network. Any other suggestions? I also checked the port number which is 7545. – CloudTech Support Jul 21 '20 at 19:04

1 Answers1

1

Another problem is that 'ganache' section is outside 'networks'.

  networks: {
    development: {
      port: 7545,
      host: "127.0.0.1",
      network_id: "*"
    },
    ganache: {
      provider: function() {
        return new HDWalletProvider(process.env.MNEMONIC, "http://127.0.0.1:7545", MetaMaskAccountIndex)     
      },
      network_id: 5777
    },
  },

Ismael
  • 30,570
  • 21
  • 53
  • 96