Solidity Pragma – Pragma Version and Imported Files in Solidity

solidity

From the docs

The version pragma is used as follows:

pragma solidity ^0.4.0;

Such a source file will not compile with a compiler earlier than version 0.4.0 and it will also not work on a compiler starting from version 0.5.0 (this second condition is added by using ^).

Then what happens if we have two files: A.sol and B.sol where A.sol is declaring pragma ^0.4.15 and at the same time imports B.sol which declares pragma ^0.4.0? How the compiler manages this mismatch?

Best Answer

The little carrot up means just use the highest one past the number. Since all compilers are less than .5, you could just use 4.18 (or whatever is highest now).

But the compiler you use isn't based off what the pragma statement is. The pragma statement is just there to tell the compiler that if there isn't a carrot or you haven't specified the version of solc downloaded, then pass you back a nice little error.

You can read more specifics here: https://github.com/ethereum/solc-js

But in general, if you want to use a previous version you have to specify to use it. It seems to me that the pragma statements are there to make sure you don't use new soldidity features with an old compiler.

Related Topic