Brownie – Addressing Compiler Version Discrepancies in Brownie Compile

brownie

Why does brownie attempt to compile with the latest locally available version of solc even if I set a specific older version in the config file?

Example:

bernat:uniswap-v3-playground bernat$ brownie compile
Brownie v1.14.5 - Python development framework for Ethereum

Compiling contracts...
  Solc version: 0.7.5
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
Generating build data...
[... removed for conciseness ...]

Generating interface ABIs...
CompilerError: solc returned the following errors:

ParserError: Source file requires different compiler version (current compiler is 0.8.1+commit.df193b15.Darwin.appleclang) - note that nightly builds are considered to be strictly less than the released version
 --> /Users/bernat/.brownie/packages/OpenZeppelin/openzeppelin-contracts@3.4.1-solc-0.7/contracts/token/ERC721/IERC721Enumerable.sol:3:1:
  |
3 | pragma solidity ^0.7.0;
  | ^^^^^^^^^^^^^^^^^^^^^^^

In this example it looks like it's trying to use 0.8.1 although at the start it acknowledges the version 0.7.5, which left me pretty confused. The only workaround I've been able to find is to delete all versions post 0.7.5.

Best Answer

In your brownie-config.yaml file, you'll be able to set a specific version of solidity. However, if a contract specifies a different version, you'll run into an error.

It looks like you're using openzeppelin's 3.4.1 version of their contracts. If you look into the package, you'll see they all use version 0.7 of solidity. You'll either have to:

  1. Remove the need for a specific verison of solidity in your brownie config
  2. Update to an openzeppelin package that uses v0.8 of solidity (may I suggest their 4.x version?)

Furthermore:

Brownie can handle multiple imports, but solidity can't.

If I have a contract with v0.6 and it imports v0.8 - solidity will freak out

If I have a contract with v0.6 and a different contract with v0.8, solidity doesn't care since they are different, and brownie is smart enough to compile them both with their own compilers.

Related Topic