Published on

Solution for Error: The network id specified in the truffle config does not match the one returned by the network

Problem: Running into error message:

Error: The network id specified in the truffle config (123) does not match the one returned by the network (456).  Ensure that both the network and the provider are properly configured.

Solution: This error usually occurs because the Ganache-cli is not using the same networkId as the one defined in the truffle.config.js file. To fix this, first make sure to define a number as the networkId in the truffle.config.js file like so:

module.exports = {
    contracts_build_directory: './frontend/src/contracts',

    networks: {
        development: {
            host: "127.0.0.1", // Localhost (default: none)
            port: 8545, // Standard Ethereum port (default: none)
            network_id: "4", // Any network (default: none)
        }
    },
...

}

Then make sure to run Ganache-cli with the networkId flag included like so:

ganache-cli --networkId 4

Conclusion

Thanks for reading this blog post!

If you have any questions or concerns please feel free to post a comment in this post and I will get back to you when I find the time.

If you found this article helpful please share it and make sure to follow me on Twitter and GitHub, connect with me on LinkedIn and subscribe to my YouTube channel.