0

I'm trying to run solc --userdoc --devdoc myContract.sol to generate natspec. However, the compiler complains that the contract has a different pragma-version. In fact the contract pragma is at ^0.6.0 and I also use an external contract interface @chainlink/contracts/src/v0.6/ChainlinkClient.sol.

When I install solc on my ubuntu machine with sudo snap install solc it installs some (the wrong) version and I don't see how I can change the install version or switch between versions.

I pip-installed the python package https://github.com/crytic/solc-select which promised to do the job. But when I run solc --version I still have the incompatible version, on which my contract wont compile.

When I use the docker images

sudo docker run -v $HOME/myProject/contracts:/contracts ethereum/solc:0.6.12 -o /contracts/output --abi --bin /contracts/myContract.sol

I get the error:

Error: Source "@chainlink/contracts/src/v0.6/ChainlinkClient.sol" not found: File outside of allowed directories.

This issue is also reported here, but this seems like a rabbit hole that I shouldn't want to get into.

2
  • 1
    solc accept list of redirect paths, check this option out
    – Nulik
    Aug 4 at 21:40
  • 1
    just download all the versions of solc you need from Releases section of Github
    – Nulik
    Aug 4 at 21:41
1

Last time I checked the instruction on the official solidity documentation page worked with solc and docker.

For example to compile /ethereum/test.sol and leave the outputs at /ethereum/build.

docker run -v /ethereum:/sources ethereum/solc:0.5.16 --abi --bin /sources/test.sol -o /sources/build
0

You can get any version of the compiler for any supported platform from solc-bin. The compiler is a single statically compiled binary so there's really not much point in running it via Docker unless you just really like that as a way to easily download it. The binary is the only file inside the docker image anyway.

To download and run 0.6.x:

curl -OL https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.6.12+commit.27d51765
chmod +x solc-linux-amd64-v0.6.12+commit.27d51765
./solc-linux-amd64-v0.6.12+commit.27d51765 --userdoc --devdoc myContract.sol

If myContract.sol contains import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol", you also need to make sure that the compiler can find that file. In 0.8.8+ you can install chainlink via npm and simply add --include-path node_modules/ to the solc command. That option was not available on 0.6.x and the workaround is to create a symlink to it inside your project directory

ln -s node_modules/@chainlink/ @chainlink

or, alternatively, use import remapping (note however that remapping affects contract metadata):

./solc-linux-amd64-v0.6.12+commit.27d51765 @chainlink/=node_modules/@chainlink/ --userdoc --devdoc myContract.sol

When I install solc on my ubuntu machine with sudo snap install solc it installs some (the wrong) version and I don't see how I can change the install version or switch between versions.

The snap package is maintained by the community on the best-effort basis and is unfortunately out of date right now (#11940). I'd really recommend to use the static binary instead.

When I use the docker images sudo docker run -v $HOME/myProject/contracts:/contracts ethereum/solc:0.6.12 -o /contracts/output --abi --bin /contracts/myContract.sol I get the error: Error: Source "@chainlink/contracts/src/v0.6/ChainlinkClient.sol" not found: File outside of allowed directories..

The compiler will refuse to import files from outside of your project directory unless you specifically tell it it's fine. You can do this using --allow-paths option. This should contain the directory where you installed chainlink.

Note that, if you're using solc from Docker, it should be a directory in container's filesystem rather than in your local filesystem. The fact that there are two parallel filesystems connected via Docker volumes is often confusing to users which is why, again, I'd recommend a static binary instead - it will make dealing with paths much more straightforward.

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.