truffle – Error: HelloWorld Not Deployed to Detected Network (Network/Artifact Mismatch)

truffletruffle-consoletruffle-deployment

I'm following the steps in this link to create a truffle project.
I'm using ganache-cli as the ethereum client.

    rajkumar@rajkumar: Ethereum$ mkdir helloworld
    rajkumar@rajkumar: Ethereum$ cd helloworld/
    rajkumar@rajkumar: helloworld$ sudo truffle init

    ✔ Preparing to download
    ✔ Downloading
    ✔ Cleaning up temporary files
    ✔ Setting up box

    Unbox successful. Sweet!

    Commands:

    Compile:        truffle compile
    Migrate:        truffle migrate
    Test contracts: truffle test

    rajkumar@rajkumar: helloworld$ truffle create contract HelloWorld
    rajkumar@rajkumar: helloworld$ sudo truffle create contract HelloWorld

Then I updated the smart contract with the one in here.

    rajkumar@rajkumar: helloworld$ sudo truffle create migration HelloWorld
    rajkumar@rajkumar: helloworld$ sudo truffle migrate --network development
    [sudo] password for rajkumar:                                                                                                      

    Compiling your contracts...
    ===========================
    > Compiling ./contracts/HelloWorld.sol
    > Artifacts written to /home/rajkumar/Coding/Ethereum/helloworld/build/contracts
    > Compiled successfully using:
    - solc: 0.5.8+commit.23d335f2.Emscripten.clang

    Network up to date. 
    rajkumar@rajkumar: helloworld$ sudo truffle console
    truffle(development)> let instance = await HelloWorld.deployed()
    Thrown:
    Error: HelloWorld has not been deployed to detected network (network/artifact mismatch)
        at processTicksAndRejections (internal/process/task_queues.js:85:5)
        at Function.deployed (/usr/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/lib/contract/constructorMethods.js:61:1)
        at Object.checkNetworkArtifactMatch (/usr/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/lib/utils.js:256:1)
    truffle(development)>

Why I'm getting above error? How can I fix this?

Best Answer

in your HelloWorld migration file from migrate folder you should open it and by the tutorial add this:

var HelloWorld = artifacts.require('HelloWorld');

module.exports = function(deployer) {
  // Use deployer to state migration tasks.
  deployer.deploy(HelloWorld);
};

you should read the truffle document for more detail: https://www.trufflesuite.com/docs/truffle/getting-started/running-migrations.

Related Topic