3

Any ideas about the reason for the following error from truffle? The contract is from the solidity docs.

Truffle.js -

//var Set = artifacts.require("./Set");
var Consumer = artifacts.require("./Consumer");
var Infofeed = artifacts.require("./Infofeed");
//var med1 = artifacts.require("./med1");
module.exports = function(deployer) {
  //deployer.deploy(Set);
  //deployer.link(Set, d3);
  deployer.deploy(Consumer);
  deployer.deploy(Infofeed);

};

Code -

pragma solidity ^0.4.18;

contract InfoFeed {
    function info() public payable returns (uint ret) { return 42; }
}

contract Consumer {
    InfoFeed feed;
    function setFeed(address addr) public { feed = InfoFeed(addr); }
    function callFeed() public { feed.info.value(10).gas(800)(); }
}

Filename - Consumer.sol

Output -

Writing artifacts to ./build/contracts

Using network 'development'.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0x8a2f45296c97a1393b9ef1b21e63ba5616944f893b70fd84c589fcf66ec7a29e
  Migrations: 0x9a57fa3522a99d6b8d19ecca976edc2168260580
Saving successful migration to network...
  ... 0xb232b7a1a42e1abf795f60686b00b301a346464c08ffbe2c0df5d955b195070e
Saving artifacts...
Running migration: 2_deploy_contracts.js

/usr/local/lib/node_modules/truffle/build/cli.bundled.js:63957
  throw new Error("Could not find artifacts for " + import_path + " from any sources");
        ^
/usr/local/lib/node_modules/truffle/build/cli.bundled.js:63957
  throw new Error("Could not find artifacts for " + import_path + " from any sources");
  ^

Error: Could not find artifacts for ./Infofeed from any sources
    at Resolver.require (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:63957:9)
    at Object.require (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176376:36)
    at ResolverIntercept.require (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:305479:32)
    at /geth/mybc/geth/zt/migrations/2_deploy_contracts.js:3:26
    at ContextifyScript.Script.runInContext (vm.js:59:29)
    at ContextifyScript.Script.runInNewContext (vm.js:65:15)
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:204344:14
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
  • Infofeed is not defined into a separate file so you can't import the artifact in that way. Try to separate the InfoFeed definition in another file and it should work – mirg Mar 14 '18 at 9:30
2

Contract InfoFeed is not deployed. To be able to use its artifact, the contract need to be deployed and to do that truffle needs to have a seperate file containing the InfoFeed contract.

then to use the Deployed Contract InfoFeed you need to link to it in your main contract (Consumer) via its address that you pass it to the constructor before deploying Consumer.

Something like this :

//var Set = artifacts.require("./Set");
var Consumer = artifacts.require("./Consumer");
var Infofeed = artifacts.require("./Infofeed");
//var med1 = artifacts.require("./med1");
module.exports = function(deployer) {
  deployer.deploy(Infofeed).then(
     DeployedContract =>{
     deployer.deploy(Consumer,DeployedContract.address);
     }
  )
  //deployer.deploy(Set);
  //deployer.link(Set, d3);
};

of course you need to change your Consumer contract and add a variable in constructor and a state variable to hold the InfoFeed deployed contract address.

All of that or you can also just import the sperated file of InfoFeed in your Consumer contract, declaing consumer as an inheritance child of InfoFeed and then deploying only the consumer contract.

  • Thanks for the comments. It was a typo! InfoFeed and not Infofeed. – Trevor Lee Oakley Mar 14 '18 at 16:29
  • i actually didn't see that, sorry. – Kaki Master Of Time Mar 15 '18 at 8:34
  • I also bump into this issue. In my case, i had my contract named differently from my filename. – Jeremy Jul 24 '18 at 9:39
1

It was a typo! InfoFeed and not Infofeed. It works with InfoFeed in the truffle.js file.

1

Make sure you have the Migrations.sol and that the name of the contract in the test is the same as the name of the file, that solved the issue for me.

0

I got the same problem just now, but I solved it in this way.

  • After your compilation, go to your_folder_location\build\contracts folder.

  • Then you will see a JSON file which not related to your contract file.

  • Just rename that JSON file same as your contract file. ( most probably that JSON file related your folder name )

  • But after that you can see the renamed file as well as the original file too, both files in same location. Don't worry.

That's it.

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.