9

I have a foundry project with files that have multiple solidity versions(0.7.x and 0.8.x). hardhat can relatively easily be configured to compile all files in the project as follows:

https://hardhat.org/hardhat-runner/docs/advanced/multiple-solidity-versions

Does foundry have built-in support for multiple solidity compiler versions? I came across a hacky way to do this which is non-ideal and I don't want to take this approach.

2
  • According to the documentation, foundry will find the list of required compilers for your project as long as you do not set the sol_version in your configuration file, see here
    – Jaime
    Commented Aug 20, 2023 at 14:08
  • @Jaime thanks, your answer is almost correct, but it's not the sol_version that should not be configured in the foundry.toml, but the solc variable that should be omitted(sol_version isn't even a valid config variable), also the auto_detect_solc should be set to true or not set at all since it defaults to true. I'd be fine with giving you the bounty, if you provide a proper answer, but it's not mine to give :)
    – MShakeG
    Commented Aug 20, 2023 at 16:59

2 Answers 2

7
+50

So it doesn't seem like Foundry allows you to manually configure multiple solc versions however Foundry does automatically detect and configure the required compilers for your project, you'll need to make sure of the following:

  • Do not explicitly configure a solidity compiler version i.e. do not set the solc variable in your foundry.toml config.

  • Ensure that auto_detect_solc is set to true or leave it unconfigured(since the default value is true).

Here's an example of what your foundry.toml might look like:

# foundry.toml

[profile.default]
auto_detect_solc = true
# Do not include the 'solc' variable

Credit to @jaime for pointing me in the right direction.

2
  • This doesn't solve explicit conflicts, if there are two or more contract with non-overlapping versions: "^0.8.0" and "<0.6".
    – jsonDoge
    Commented Oct 29 at 10:35
  • @jsonDoge can you elaborate on your issue? I don't follow
    – MShakeG
    Commented Oct 30 at 12:35
0

In the case that auto_detect_solc = true doesn't work, just set the compiler version for accurate testing.

#foundry.toml
// Specify Version
solc_version = "0.8.22"
//auto_detect_solc = true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.