0

I'm trying to call a contract I've created.
I've set up my truffle deployment script like so:

var SafeYieldAggregator = artifacts.require("SafeYieldAggregator")

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

I've Run:

truffle compile truffle migrate

Which returns the output:

Compiling your contracts... =========================== √ Fetching solc version list from solc-bin. Attempt #1 Everything is up to date, there is nothing to compile.

Inside my app I attach my truffle contract $.getJSON('SafeYieldAggregator.json', function(data) { // Get the necessary contract artifact file and instantiate it with @truffle/contract var safeYieldArtifact = data; App.contracts.SafeYieldAggregator = TruffleContract(safeYieldArtifact);

  // Set the provider for our contract
  App.contracts.SafeYieldAggregator.setProvider(App.web3Provider);
});

And then I try to call my contract:

 App.contracts.SafeYieldAggregator.deployed().then(function(instance) {
    yieldAggregatorInstance = instance;

    // Execute adopt as a transaction by sending account
    return yieldAggregatorInstance.supply(1, {from: account});
  })

I get an error:

Contract has not been deployed to detected network (network/artifact mismatch)

My best guess is that truffle thinks this has been deployed appropriately. My config is setup like:

networks: {
  development: {
    host: "127.0.0.1",
    port: 8545,
    network_id: "*" // Match any network id
  },
  develop: {
    port: 8545
  }
}

and I'm running the ganache-cli on the same port forking the main net

1

You can try executing the following command:

 truffle develop
 compile -all
 migrate --reset 

If this still doesn't work, make some changes to your contract, such as adding a space.You can try, and God bless you!

1
  • Thanks I'll check this out tomorrow
    – johnny 5
    Jul 26 '21 at 2:54
0

It could be because you executed that JS migration file before. If you do truffle migrate, Truffle will not run previous successful migrations again (even though you modified your contract). You can read more about it under When are migrations executed https://blockheroes.dev/complex-migration/.

To redeploy all contracts again just run truffle migrate --reset

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.