Compiling AggregatorV2V3Interface leads to TypeError: Interfaces cannot inherit. interface

Viewed 753

SOlidity course: Brownie Fund Me Lesson 6: https://github.com/PatrickAlphaC/brownie_fund_me

Compiling AggregatorV2V3Interface leads to TypeError: Interfaces cannot inherit. interface I have added a file MockV3Aggregator.sol under contract->test to deploy a mock. However, when I use "brownie compile" I get the following errors:

PS C:\Users\user\Documents\BC\demos\brownie_fund_me> brownie compile
INFO: Could not find files for the given pattern(s).
Brownie v1.18.1 - Python development framework for Ethereum

Compiling contracts...
 Solc version: 0.6.0
 Optimizer: Enabled  Runs: 200
 EVM Version: Istanbul
CompilerError: solc returned the following errors:

C:/Users/user/.brownie/packages/smartcontractkit/chainlink-brownie- 
contracts@1.1.1/contracts/src/v0.6/interfaces/AggregatorV2V3Interface.sol:7:38: 
TypeError: Interfaces 
cannot inherit.
interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface
                                 ^-----------------^

C:/Users/user/.brownie/packages/smartcontractkit/chainlink-brownie- 
contracts@1.1.1/contracts/src/v0.6/interfaces/AggregatorV2V3Interface.sol:7:59: 
TypeError: Interfaces 
cannot inherit.
interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface
                                                      ^-------------------^
4 Answers

You might get this error in brownie , hardhat or any other dev framework. This will occur when your code is trying to access chainlink contracts.

Ex - import "@chainlink/contracts/src/v0.6/tests/MockV3Aggregator.sol";

MockV3Aggregator need to access other interfaces too.

Solution

  1. Try to increase solidity compiler version towards 0.6.5, 0.6.6 and so on. It works well for me if I Use 0.6.6.

Changing the compiler version in VSCode with the solidity plugin via right click "Solidity: change workspace compiler version (Remote)" to 0.6.0 or anything above won't help.

Brownie will ignore this and try to get the highest version in the range of your pragma solidity starting point. pragma solidity >=0.6.0 <0.9.0; The starting point here is 0.6.0 so Brownie will use 0.6.12 and try to compile this file regardless of the settings of VSCode.

Solution: Very simple, change the starting point into something higher and Brownie will use the correct solc.

pragma solidity >=0.8.0 <0.9.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

Not so simple ... This might break your code. So some editing might be in order.

I had the same issue following the same tutorial. In the brownie-config.yml file you just need to add:

version = 0.6.6 Under the solc section (which is under the compiler section).

This means that it's a problem with the compiler version, which apparently cannot be easily modified via Visual Studio Code as I thought

changing pragma solidity to 0.8.0 instantly compiled the contract.

Related