npmblockchainsmartcontractstruffleganache

Smart contract is not deployed in my current network?


I'm new to blockchain. I setup a ganache network, added it to metamask. I'm trying to start an npm server and it works. On npm start, I'm being redirected to localhost:3000, where there are 4 options. But after I click on one of them, it's supposed to open MetaMask and make the transaction but I keep getting the error message on top of my browser that says "Smart contract is not deployed in the current network": Error

Here's my truffle-config.js:

module.exports = {
 

  contracts_build_directory: './client/src/artifacts',
  networks: {
    development: {
      host: "127.0.0.1",   
      port: 7545,            
      network_id: "5777",       
    },

And the 2_deploy_contracts.js file:

const SupplyChain = artifacts.require("SupplyChain");

module.exports = function (deployer) {
    deployer.deploy(SupplyChain);
};

I added my truffle-config.js file into the ganache workspace settings and tried to migrate --reset several times but nothing fixed it. What could be the issue and how do I resolve it?


Solution

  • You are close to getting it work, just do few debugging. First, open your browser and be sure you are  on the Ganache network. In your browser dev console, type
    ethereum.request({ method: 'eth_chainId' })

    You should get 0x1691 which is the chain id - 5777.

    Let me know what you got