3

I'm having a hard time trying to configure Ganache as a network on Hardhat.

networks: {
  ganache: {
    url: "http://127.0.0.1:7545",
    chainId: "7777",
    accounts: [
      `0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d`,
      `0xe485d098507f54e7733a205420dfddbe58db035fa577fc294ebd14db90767a52`,
    ],
  },
},

I got this error message:

Error HH8: There's one or more errors in your config file:

  * Invalid value {"url":"http://127.0.0.1:7545","chainId":"7777","accounts":["0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d","0xe485d098507f54e7733a205420dfddbe58db035fa577fc294ebd14db90767a52"]} for HardhatConfig.networks.ganache - Expected a value of type HttpNetworkConfig.

Is it possible to do this configuration and use Ganache as a local network?

1
  • Try using " instead of ` Commented Mar 18, 2022 at 8:32

3 Answers 3

3

I realized that to use Ganache as my local blockchain with Hardhat,I just have to start Ganache with chainId expected by Hardhat, 31337, and I don't have to do anything in the networks section of hardhat-config.js:

ganache -p 8545 --chain.chainId 31337 
0

While you are correct that it seems to need a chainId of 1337 to work properly (changing the value of chainId will cause an error, albeit one different from the one you got) the issue you're seeing there is that you have defined the value of chainId as a string and not a number.

I am using Ganache AppImage, so I am unable to change the chainId as you show above, but you could try your example with 7777 (without the quotes) if you use the CLI and can set a different chain ID

0

I think there is no need to add chain id I have run ganach on my local machine Below is the hardhat configuration file

    module.exports = {
  solidity: "0.8.17",
  networks: {
    hardhat: {
      chainId: 1337,
    },
    ganache: {
      url: "http://127.0.0.1:7000",
      accounts: [
        `7bc522e9ba27f118ad4157771bec290f59ffffe45ee66bb81f137043150bd2`,
      ],
    }

  },
  paths: {
    artifacts: "./src/artifacts",
  }
};

After these run following command and it will deploy contract on ganache network

npx hardhat run scripts/deploy.js --network ganache

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.