23

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)
4
  • 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
    – qbsp
    Commented Mar 14, 2018 at 9:30
  • Documentation for VS COde plugin has a section on OpenZepplin. That solved my problem
    – Amarsh
    Commented Nov 15, 2021 at 23:38
  • github.com/trufflesuite/truffle/issues/… you need to give contract names , not the contract file's names Commented Jan 19, 2022 at 23:48
  • My friend, in your truffle.js you are trying to import Infofeed but the name of your contract is InfoFeed (check the second F) Commented Mar 25, 2023 at 20:42

12 Answers 12

18

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.

1
  • What if you don't see a json file related to your contract
    – johnny 5
    Commented Jul 30, 2021 at 1:01
11

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.

5

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

3

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.

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

I was seeing this when my build/contracts directory had some old files in it. This is an easy fix:

rm -rf build
npx truffle compile && npx truffle migrate && npx truffle test
2

Its a typo error! Whenever you get this error, first thing to check is whether you contract name declared in contract inside /contracts directory is same as the json file that is created in /build/contracts directory.

2

Had the same error though for me it was a wrong path in one of my files

1

So, I got the solution to this problem. This issue is already been posted on github. Basically most of us are replacing wrong parameters in our migration folder containing .js files.

As told on the GitHub we need to replace the parameter of the .js files by the names of our contract name present in our respective .sol files.

(you might me replacing them with the .sol file names which is wrong)

This will resolve the issue.

Source :- https://github.com/trufflesuite/truffle/issues/4620

credit goes to - @kommradHomer

0

I had a similar issue:

Error: Could not find artifacts for Migrations from any sources

I started my project from scratch by creating the contracts folder and then creating my contracts, BUT then I decided to bring TRUFFLE to my project, so I did

$ truffle init

I selected (N) to overwrite the contracts folder. The problem was that the migrations folder contain a file that was referencing a contract file called Migrations that did not exists.

To solve it, I initialized my project again and this time I selected (Y) to overwrite the contracts folder. My current contracts did not get deleted since I have them opened in VSC and I had to re-saved them.

0

Try and rename .sol file in the contract folder to any name that you want. Then truffle migrate again.

0

The actual problem is that you're supplying the wrong argument to artifacts.require; it takes the name of the contract name i.e., you should do artifacts.require("Customer"), not artifacts.require("./Customer"). In order to provide some limited compatibility with older versions of Truffle, we've made it so that using the name of the file will also sometimes work, but, as you've seen, this is not fully reliable. I'm not familiar enough with that part of the code to know why it's hitting an error in this particular case, but the right way to solve your problem is to pass the contract name, not the file name, to artifacts.require.

0

I had this issue when having switched to wrong node version using nvm.

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