I have a Solidity project. It has contracts folder and few subfolders. Now I have to compile it with Truffle, but it seems to me the tool doesn't support the case when contracts are not in "contracts/" folder.

I've found it could be done via solc options in truffle.js, but I can't figure out what should I place there. Could you help me? Thanks

  • You can require them in the main contract to get it compiled. – niksmac Dec 25 '17 at 2:30
  • No, this is not what I'm looking for. require checks a statement and I'm talking about a project with few levels of directories. Truffle thinks every contract is in "contracts/" directory, but in my case there are "contracts/foundation/", "contracts/common/" etc – Vourhey Dec 25 '17 at 8:06
  • 1
    Looks like your requirement is not to get the contract deployed/compiled but to arrange the contracts in folder and then do deploy/compile. If it is multiple contracts, you can use the migrations file to get it compiled and deployed. – niksmac Dec 25 '17 at 15:07
  • Also consider reading XY Problem – niksmac Dec 25 '17 at 15:10
  • Ok, let me explain again. I've already have a contracts folder with subfolders. I can compile it with solc and its options. Smart-contracts have "import ...." and it has subfolder's name. So now I have to create ethpm package. Truffle can do it, but only when *.sol files are int contracts folder, not subfolders – Vourhey Dec 26 '17 at 16:14

As i understand your problem it can be simply stated as follows:

This could be your Dapp structure:


Now you have these


When you run

truffle compile

It doesn't compile all of them, only those directly accessible.

Now your simple solution, run this:

truffle compile --all

this commands tells truffle to look for every .sol extension file anywhere in contracts folder and compile it.

| improve this answer | |
  • Ok, thanks! That's something. Unfortunately after this there was another issue. Now I have to publish my contracts to ethpm. The issue is described here github.com/trufflesuite/truffle/issues/699 but nobody answers – Vourhey Dec 26 '17 at 22:35
  • You can't do that. You cannot combine all the dependencies into a single package. If you have ever installed a NPM package then you might have noticed that all the dependencies are installed separately,and then they are used by combining them, similarly you need to publish them separately, and when some body installs your main package he would also download and install its dependencies, for the main package to work. This approach is much better and makes debugging easy. – Kashish Khullar Dec 27 '17 at 10:53

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.