0

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?

1

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.

2

It looks like you deployed to the development network but are running truffle console with the default network, so assume that these are different.

You should deploy and use the console on the same network.

truffle migrate --network development
truffle console --network development

As an aside, you shouldn't have to use sudo. You may want to consider installing packages locally.
I only have ganache-cli installed globally.
https://forum.openzeppelin.com/t/installing-packages-locally-rather-than-globally-npx/663

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.