0

I am trying to compile a file using solcjs from a command-line, and running into various problems.

First of all, I need to supply in the command-line all the files that are imported by the primary file.

Otherwise I get ParserError: Source "SomeFile.sol" not found: File not supplied initially.

But when I do supply these files, I get a bunch of other problems.

The main issue seems to be the fact the one of the imported files resides in a sub-folder.

First I noticed that I cannot use a backslash, i.e., can only use a slash (I should emphasize that I am running on Windows).

So I've fixed that.

Then I noticed that I cannot use a relative path, i.e., must use the full path of the file.

So I've fixed that too.

I was able to detect and solve these problems by attempting to compile that specific file by itself.

Now back to my original goal - once I specify this file in the list of files passed to solcjs, I keep getting that File not supplied initially error.

Here is the command line that I am using:

solcjs --optimize --bin --abi -o build C:/project/util/file1.sol file2.sol main.sol

When I compile each one of the imported files separately, I get abi and bin files inside the build output directory:

solcjs --optimize --bin --abi -o build C:/project/util/file1.sol
solcjs --optimize --bin --abi -o build file2.sol

But no matter what I do, I am unable to compile the main file.

Compiler version is 0.4.15+commit.bbb8e64f.Emscripten.clang.

Thank you.

2

If you are not trying to compile files on the terminal only and can use javascript to do that then this script might help you which I wrote sometime back. I also had multiple dependent contract files which were required to compile the main contract. So I solved using following way -

Define all dependent contracts in an input object keeping the same import order and then use that object to compile your contract.

var input = {
    'strings.sol': fs.readFileSync('strings.sol', 'utf8'),
    'StringLib.sol': fs.readFileSync('StringLib.sol', 'utf8'),
    'Killable.sol': fs.readFileSync('Killable.sol', 'utf8'),
    'Ownable.sol': fs.readFileSync('Ownable.sol', 'utf8'),
    'LMS.sol': fs.readFileSync('LMS.sol', 'utf8')
};
let compiledContract = solc.compile({sources: input}, 1);

Hope this helps.

Note: This requires basic nodejs knowledge.

  • Yes, I already saw this answer elsewhere in here. But how exactly should I execute this script? Thank you. – goodvibration Aug 23 '17 at 11:08
  • With the help of NodeJs, install nodejs on your machine and then run "node script.js" – Sanchit Aug 23 '17 at 11:11
  • I get ReferenceError: fs is not defined. – goodvibration Aug 23 '17 at 11:21
  • 1
    run "npm install fs" – Sanchit Aug 23 '17 at 11:23
  • it worked?, if then let me know I'll help you out in through chat option. – Sanchit Aug 23 '17 at 11:38

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.