1

I'm trying to understand how to use solidity's JSON input-output API. Here's my json file;

{
  "language": "Solidity",
  "sources": {
    "StandardToken.sol": {
      "urls": [
        "file:///home/myuser/myproject/contracts/vendor/StandardToken.sol"
      ]
    }
  }
}

My best guess as to the "correct" command is;

cat input.json | solc --allow-paths /home/myuser/myproject/contracts --standard-json

I've tried lots of different relative paths, ending with or without a trailing slash, running the command in different directories, etc. But no matter what combination I try, I get back a json object with this error message;

"Cannot import url (\"file:///home/myuser/myproject/contracts/vendor/StandardToken.sol\"): File import callback not supported"

I was getting this on solc version 0.4.24, but I upgraded to 0.5.1+commit.c8a2cb62.Linux.g++ and get the same issue.

Strangely, I get a similar message with solcjs;

$ cat input.json | solcjs --standard-json
Cannot import url (\"file:///home/myuser/myproject/contracts/vendor/StandardToken.sol\"): File import callback not supported

There seem to be a lot of github issues mentioning these error messages, but I can't make use of any of them.

1

When I change input.json to the following, without "file://" and with back-slashes instead of forward-slashes, solc is able to import the URL.

{
  "language": "Solidity",
  "sources": {
    "StandardToken.sol": {
      "urls": [
        "\home\myuser\myproject\contracts\vendor\StandardToken.sol"
      ]
    }
  }
}
  • If you look at the question first code bloc it seems that the path is not backslash formated – Nicolas Massart Dec 19 '18 at 14:16
  • That works! I don't think it's a thing about Window vs Ubuntu, though. My understanding is that the file:// prefix is there to distinguish it from the other options, like bzzr:// and ipfs:// that are in the example documentation. So the fact that it doesn't work makes me think there's either a bug or the documentation is out of date. Do you mind updating your answer to make the "removed the file:// prefix" more prominent? – Alex Altair Dec 19 '18 at 19:16
  • ...it also doesn't fix it for solcjs, which was my original use case. :/ – Alex Altair Dec 19 '18 at 19:37
  • I edited the answer as requested. – unrgnl Dec 19 '18 at 19: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.