To compile all of the contract sources within the
contracts/ subfolder of a project:
$ brownie compile
Each time the compiler runs, Brownie compares hashes of each contract source against hashes of the existing compiled versions. If a contract has not changed it is not recompiled. If you wish to force a recompile of the entire project, use
brownie compile --all.
If one or more contracts are unable to compile, Brownie raises an exception with information about why the compilation failed. You cannot use Brownie with a project as long as compilation is failing. You can temporarily exclude a file or folder from compilation by adding an underscore (
_) to the start of the name.
Brownie supports Solidity (
>=0.4.22) and Vyper (
0.1.0-b16). The file extension determines which compiler is used:
Project contracts can import interfaces from the
interfaces/ subfolder. Interfaces are not considered primary components of a project. Adding or modifying an interface only triggers a recompile if a contract is dependent upon that interface.
interfaces/ folder is of particular use in the following situations:
- When using Vyper, where interfaces are not necessarily compilable source code and so cannot be included in the
- When using Solidity and Vyper in the same project, or multiple versions of Solidity, where compatibility issues prevent contracts from directly referencing one another.
Settings for the compiler are found in
evm_version: null minify_source: false solc: version: 0.6.0 optimize: true runs: 200
Modifying any compiler settings will result in a full recompile of the project.
Setting the Compiler Version¶
Brownie supports Solidity versions
>=0.4.22 and Vyper version
If a compiler version is set in the configuration file, all contracts in the project are compiled using that version. It is installed automatically if not already present. The version should be given as a string in the format
If the version is set to
null, Brownie looks at the version pragma of each contract and uses the latest matching compiler version that has been installed. If no matching version is found, the most recent release is installed.
Setting the version via pragma allows you to use multiple versions in a single project. When doing so, you may encounter compiler errors when a contract imports another contract that is meant to compile on a higher version. A good practice in this situation is to import interfaces rather than actual contracts, and set all interface pragmas as
The EVM Version¶
evm_version is set to
null. Brownie sets the ruleset based on the compiler:
- byzantium: Solidity
- petersburg: Solidity
- istanbul: Solidity
You can also set the EVM version manually. Valid options are
istanbul. You can also use the Ethereum Classic rulesets
agharta, which are converted to their Ethereum equivalents prior to being passed to the compiler.
Compiler optimization is enabled by default. Coverage evaluation was designed using optimized contracts, there is no need to disable it during testing.
See the Solidity documentation for more info on the
true, the contract source is minified before compiling. Each time Brownie is loaded it will then minify the current source code before checking the hashes to determine if a recompile is necessary. This allows you to modify code formatting and comments without triggering a recompile, at the cost of increased load times from recalculating source offsets.
Installing the Compiler¶
If you wish to manually install a different version of
>>> from brownie.project.compiler import install_solc >>> install_solc("0.5.10")