Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I started to get compile error after adding openzepplin ownable contract. I'm really confused and can't find solution.

Could you please someone help me about it?

Screen Shot 2021-12-08 at 17 19 01

Screen Shot 2021-12-08 at 17 31 25

Screen Shot 2021-12-08 at 17 19 33

You must be logged in to vote

Hello @gorkemkeles it happens when the pragma solidity is not the same as the one your compiler is using, however I wonder which vscode extension are you using? The Solidity extension by Juan Blanco allows to compile different versions as far the one you are using is superior than the required.

also change this:

solidity >=0.6.0 <0.9.0

to this

solidity ^0.6.0

Finally if you have linting warning you could refer to this apart.

Replies: 6 comments · 34 replies

Comment options

Hello @gorkemkeles it happens when the pragma solidity is not the same as the one your compiler is using, however I wonder which vscode extension are you using? The Solidity extension by Juan Blanco allows to compile different versions as far the one you are using is superior than the required.

also change this:

solidity >=0.6.0 <0.9.0

to this

solidity ^0.6.0

Finally if you have linting warning you could refer to this apart.

image

You must be logged in to vote
1 reply
@gorkemkeles
Comment options

I changed solidity ^0.6.0 still getting an error like this:

Screen Shot 2021-12-08 at 18 02 57

I'm using the same vscode extension:

Screen Shot 2021-12-08 at 18 01 41

Answer selected by cromewar
Comment options

Look your current compiler version is this one:
image
And as I said it would work with different versions as far as the one you are using is equal or superior, so on any contract you have opened on vscode, push right click and change it to 0.8.0
image
image

You must be logged in to vote
25 replies
@WeTheArtist
Comment options

I also noticed that in the brownie-config.yaml file :smartcontractkit/chainlink-brownie-contracts@1.1.1 was written differently in dependencies and remappings. However, after making both of them the same it still has the same errors. I am trying several things to try and see if I can match the versions somehow. I think I cannot proceed ahead if the code doesn't compile right?

dependencies:
  - smartcontractkit/chainlink-brownie-contracts@0.2.1
  - OpenZeppelin/openzeppelin-contracts@4.3.0
compiler:
  solc:
    remappings:
      - '@chainlink=smartcontractkit/chainlink-brownie-contracts@0.2.1'
      - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.3.0'
networks:
  mainnet-fork:
    eth_usd_price_feed: '0xaEA2808407B7319A31A383B6F8B60f04BCa23cE2'
@cromewar
Comment options

I also noticed that in the brownie-config.yaml file :smartcontractkit/chainlink-brownie-contracts@1.1.1 was written differently in dependencies and remappings. However, after making both of them the same it still has the same errors. I am trying several things to try and see if I can match the versions somehow. I think I cannot proceed ahead if the code doesn't compile right?

dependencies:
  - smartcontractkit/chainlink-brownie-contracts@0.2.1
  - OpenZeppelin/openzeppelin-contracts@4.3.0
compiler:
  solc:
    remappings:
      - '@chainlink=smartcontractkit/chainlink-brownie-contracts@0.2.1'
      - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.3.0'
networks:
  mainnet-fork:
    eth_usd_price_feed: '0xaEA2808407B7319A31A383B6F8B60f04BCa23cE2'

Yep you won't be able to continue if the code does not compile, please refer to the instructions I posted above and see if they work for you.

@WeTheArtist
Comment options

HI @cromewar ,
Thank you, I did all the steps that you mentioned but it is still giving the same problem.

"delete the build folder again.
on this options:
image
Change both, the workspace and the global compiler version.
change the chainllink-brownie-contracts versions to 0.3.0 (which is actually the latest)
go to C:/Users/rosne/ and delete the .brownie folder.
try to compile again."

Do you think that it could be because the imports that we do are for specific versions of solidity?
I am not sure if I am thinking correctly, but is it possible that if 2 out of the 3 imports run with solidity 0.8.0 and 1 with 0.6.0?

I am very new to coding and I really like web3, so if I am asking stupid questions then please ignore it. :)

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol";

Would uninstalling VS code and all its packages help?

@cromewar
Comment options

Not stupid questions at all, there are not stupid questions, the versions are retro compatible as far as they has this ^ symbol which indicates that the compiler should use that and any other above version available, but the references are no, so If you have changed the compiler version to ^0.8.0 on the contract, you should also change this line:

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";

To this line:

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

@cromewar
Comment options

Another solution is just use the compiler on version 0.8.0 selected on vscode, but keeping the compiler version on your contract to ^0.6.0 which should work and you would have to change the import.

Comment options

Thank you @cromewar , so when I tried the solution with changing the compiler version to ^0.8.0 and import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
the error changed:

terminal:

PS D:\Python projects\Solidity dev\demo\smartcontract-lottery> brownie compile
INFO: Could not find files for the given pattern(s).
Brownie v1.17.2 - Python development framework for Ethereum

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

TypeError: Function has override specified but does not override anything.
  --> contracts/Lottery.sol:71:9:
   |
71 |         override
   |         ^^^^^^^^


TypeError: Contract "Lottery" should be marked as abstract.
 --> contracts/Lottery.sol:8:1:
  |
8 | contract Lottery is VRFConsumerBase, Ownable {
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: Missing implementation:
   --> C:/Users/rosne/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@0.3.0/contracts/src/v0.8/VRFConsumerBase.sol:116:3:
    |
116 |   function fulfillRandomness(bytes32 requestId, uint256 randomness) internal virtual;
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
  --> contracts/Lottery.sol:25:5:
   |
25 |     constructor(
   |     ^ (Relevant source part starts here and spans across multiple lines).

PS D:\Python projects\Solidity dev\demo\smartcontract-lottery> 

On changing the compiler on version 0.8.0 selected on vscode, but keeping the compiler version on your contract to ^0.6.0,
So i think change as below:

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol";

and for 0.8.0 onvs code changing the Solidity: change global compiler version(remote) to 0.8.0 right?

i get another error:

terminal:

PS D:\Python projects\Solidity dev\demo\smartcontract-lottery> brownie compile
INFO: Could not find files for the given pattern(s).
Brownie v1.17.2 - Python development framework for Ethereum

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

C:/Users/rosne/.brownie/packages/OpenZeppelin/openzeppelin-contracts@4.3.0/contracts/access/Ownable.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.6.12+commit.27d51765.Windows.msvc) - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.8.0;
^---------------------^

C:/Users/rosne/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@0.3.0/contracts/src/v0.8/VRFConsumerBase.sol:2:1: ParserError: Source file requires different compiler version (current compiler is 0.6.12+commit.27d51765.Windows.msvc) - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.8.0;
^---------------------^

PS D:\Python projects\Solidity dev\demo\smartcontract-lottery> 

I really appreciate you trying to help here.
:)

You must be logged in to vote
3 replies
@cromewar
Comment options

This ``changing the compiler version to ^0.8.0 and import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";` is or best way to go, now please share your Lottery contract code here, so we could check it, as the errors are actually fixable on your code.

@WeTheArtist
Comment options

Keeping my fingers crossed that there is something wrong in the code and we can fix it :)

Lottery.sol:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol";

contract Lottery is VRFConsumerBase, Ownable {
    uint256 usdEntryFee;
    address payable[] public players;

    address payable public recentWinner;
    uint256 public randomness;
    AggregatorV3Interface internal ethUsdPriceFeed;
    enum LOTTERY_STATE {
        OPEN,
        CLOSED,
        CALCULATING_WINNER
    }

    LOTTERY_STATE public lottery_state;
    uint256 public fee;
    bytes32 public keyhash;

    constructor(
        address _priceFeedAddress,
        address _vrfCoordinator,
        address _link,
        uint256 _fee,
        bytes32 _keyhash
    ) public VRFConsumerBase(_vrfCoordinator, _link) {
        usdEntryFee = 50 * (10**18);
        ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
        lottery_state = LOTTERY_STATE.CLOSED;
        fee = _fee;
        keyhash = _keyhash;
    }

    function enter() public payable {
        //$50 min
        require(lottery_state == LOTTERY_STATE.OPEN);
        require(msg.value >= getEntranceFee(), "Not enough ETH!");
        players.push(payable(msg.sender));
    }

    function getEntranceFee() public view returns (uint256) {
        (, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
        uint256 adjustedPrice = uint256(price) * 10**12; //18 decimals
        //$50, 2000 ETH
        //50/2000
        //50*10000/2000
        uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice;
        return costToEnter;
    }

    function startLottery() public onlyOwner {
        require(
            lottery_state == LOTTERY_STATE.CLOSED,
            "cant start a new lottery yet"
        );
        lottery_state = LOTTERY_STATE.OPEN;
    }

    function endLottery() public onlyOwner {
        lottery_state = LOTTERY_STATE.CALCULATING_WINNER;
        bytes32 requestId = requestRandomness(keyhash, fee);
    }

    function FulfillRandomness(bytes32 _requestId, uint256 _randomness)
        internal
        override
    {
        require(
            lottery_state == LOTTERY_STATE.CALCULATING_WINNER,
            "you arent there yet!"
        );

        require(_randomness > 0, "random not found");
        uint256 indexOfWinner = _randomness % players.length;
        recentWinner = players[indexOfWinner];
        recentWinner.transfer(address(this).balance);

        //reset

        players = new address payable[](0);
        lottery_state = LOTTERY_STATE.CLOSED;
        randomness = _randomness;
    }
}
@cromewar
Comment options

Ok I was able to reproduce the problem and now I'm certain what's happening. As there a lot of changes on sol 0.8.0 we should better stay at 0.6.0, so first of all change the import and the compiler back to 0.6.0.

So where is the problem? I'm going to guess but your brownie config look like this:

dependencies:
  - smartcontractkit/chainlink-brownie-contracts@0.3.0
  - OpenZeppelin/openzeppelin-contracts@4.3.0
compiler:
  solc:
    remappings:
      - '@chainlink=smartcontractkit/chainlink-brownie-contracts@0.3.0'
      - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.3.0'
dotenv: .env

Note: you can return to 1.1.1 con chainlink-brownie-contracts.

The problem might be the openzeppelin import, as it was asking you for compiler version 0.8.0, if you have 4.3.0 is actually incorrect for this contract, the correct version for this is 3.4.0. Was I correct?

Comment options

I reverted back all the changes so now, the code looks as below and the compiler is

Retrieving compiler information:
Compiler using remote version: 'v0.6.0+commit.26b70077', solidity version: 0.6.0+commit.26b70077.Emscripten.clang

Lottery.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol";

contract Lottery is VRFConsumerBase, Ownable {
    uint256 usdEntryFee;
    address payable[] public players;

    address payable public recentWinner;
    uint256 public randomness;
    AggregatorV3Interface internal ethUsdPriceFeed;
    enum LOTTERY_STATE {
        OPEN,
        CLOSED,
        CALCULATING_WINNER
    }

    LOTTERY_STATE public lottery_state;
    uint256 public fee;
    bytes32 public keyhash;

    constructor(
        address _priceFeedAddress,
        address _vrfCoordinator,
        address _link,
        uint256 _fee,
        bytes32 _keyhash
    ) public VRFConsumerBase(_vrfCoordinator, _link) {
        usdEntryFee = 50 * (10**18);
        ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
        lottery_state = LOTTERY_STATE.CLOSED;
        fee = _fee;
        keyhash = _keyhash;
    }

    function enter() public payable {
        //$50 min
        require(lottery_state == LOTTERY_STATE.OPEN);
        require(msg.value >= getEntranceFee(), "Not enough ETH!");
        players.push(payable(msg.sender));
    }

    function getEntranceFee() public view returns (uint256) {
        (, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
        uint256 adjustedPrice = uint256(price) * 10**12; //18 decimals
        //$50, 2000 ETH
        //50/2000
        //50*10000/2000
        uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice;
        return costToEnter;
    }

    function startLottery() public onlyOwner {
        require(
            lottery_state == LOTTERY_STATE.CLOSED,
            "cant start a new lottery yet"
        );
        lottery_state = LOTTERY_STATE.OPEN;
    }

    function endLottery() public onlyOwner {
        lottery_state = LOTTERY_STATE.CALCULATING_WINNER;
        bytes32 requestId = requestRandomness(keyhash, fee);
    }

    function FulfillRandomness(bytes32 _requestId, uint256 _randomness)
        internal
        override
    {
        require(
            lottery_state == LOTTERY_STATE.CALCULATING_WINNER,
            "you arent there yet!"
        );

        require(_randomness > 0, "random not found");
        uint256 indexOfWinner = _randomness % players.length;
        recentWinner = players[indexOfWinner];
        recentWinner.transfer(address(this).balance);

        //reset

        players = new address payable[](0);
        lottery_state = LOTTERY_STATE.CLOSED;
        randomness = _randomness;
    }
}

brownie-config.yaml:

dependencies:
  - smartcontractkit/chainlink-brownie-contracts@1.1.1
  - OpenZeppelin/openzeppelin-contracts@3.4.0
compiler:
  solc:
    remappings:
      - '@chainlink=smartcontractkit/chainlink-brownie-contracts@1.1.1'
      - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@3.4.0'
dotenv: .env
networks:
  mainnet-fork:
    eth_usd_price_feed: '0xaEA2808407B7319A31A383B6F8B60f04BCa23cE2'

test_lottery.py

# 0,01243301712
# 12000000000000000

from brownie import Lottery, accounts, config, network
from web3 import Web3

# from brownie.network import account


def test_get_entrance_fee():
    account = accounts[0]
    lottery = Lottery.deploy(
        config["networks"][network.show_active()]["eth_usd_price_feed"],
        {"from": account},
    )

    # assert lottery.getEntraceFee() > Web3.toWei(0.011, "ether")
    # assert lottery.getEntraceFee() < Web3.toWei(0.015, "ether")

So I changed the brownie-config.yaml file with 1.1.1 for chainlink-brownie-contracts and openzeppelin import to 3.4.0 (as in the video).

So at the moment, I am getting a different error in the terminal after running brownie compile
Terminal:

PS D:\Python projects\Solidity dev\demo\smartcontract-lottery> brownie compile
INFO: Could not find files for the given pattern(s).
Brownie v1.17.2 - Python development framework for Ethereum

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

contracts/Lottery.sol:71:9: TypeError: Function has override specified but does not override anything.
        override
        ^------^

contracts/Lottery.sol:8:1: TypeError: Contract "Lottery" should be marked as abstract.
contract Lottery is VRFConsumerBase, Ownable {
^ (Relevant source part starts here and spans across multiple lines).
C:/Users/rosne/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@1.1.1/contracts/src/v0.6/VRFConsumerBase.sol:121:3: Missing implementation:
  function fulfillRandomness(bytes32 requestId, uint256 randomness)
  ^ (Relevant source part starts here and spans across multiple lines).

PS D:\Python projects\Solidity dev\demo\smartcontract-lottery>
You must be logged in to vote
1 reply
@cromewar
Comment options

Yes the fullfilRandomness is an abstract function which should be overrided in order to work properly, you will do that after during the course so for now just remove the override keyword from that function.

Comment options

Yes i tried that as well, the error changed , now when i compile:


PS D:\Python projects\Solidity dev\demo\smartcontract-lottery> brownie compile
INFO: Could not find files for the given pattern(s).
Brownie v1.17.2 - Python development framework for Ethereum

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

contracts/Lottery.sol:8:1: TypeError: Contract "Lottery" should be marked as abstract.
contract Lottery is VRFConsumerBase, Ownable {
^ (Relevant source part starts here and spans across multiple lines).
C:/Users/rosne/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@1.1.1/contracts/src/v0.6/VRFConsumerBase.sol:121:3: Missing implementation:
  function fulfillRandomness(bytes32 requestId, uint256 randomness)
  ^ (Relevant source part starts here and spans across multiple lines).

PS D:\Python projects\Solidity dev\demo\smartcontract-lottery> 
You must be logged in to vote
4 replies
@cromewar
Comment options

My bad as they are abstract you must 100% override the function otherwise it would complain saying it should be abstract too, so please delete the build folder and copy and paste this:

function fulfillRandomness(bytes32 _requestId, uint256 _randomness)
        internal
        override
    {
        require(
            lottery_state == LOTTERY_STATE.CALCULATING_WINNER,
            "You aren't there yet!"
        );
        require(_randomness > 0, "random-not-found");
        uint256 indexOfWinner = _randomness % players.length;
        recentWinner = players[indexOfWinner];
        recentWinner.transfer(address(this).balance);
        // Reset
        players = new address payable[](0);
        lottery_state = LOTTERY_STATE.CLOSED;
        randomness = _randomness;
    }
@WeTheArtist
Comment options

Thanks A TON @cromewar , this worked!
Was it because of the FulfillRandomness instead of fulfillRandomness at the end? So all the trouble was because of one capital F ?

@cromewar
Comment options

Yes it was, really hard to find tough. But I'm glad is solved now.

@neerajnerlekar
Comment options

Thanks for this @cromewar @WeTheArtist , even I had misspelled 'fulfillRandomness' which was giving similar errors.

Comment options

I started to get compile error after adding openzepplin ownable contract. I'm really confused and can't find solution.

Could you please someone help me about it?

Screen Shot 2021-12-08 at 17 19 01

Screen Shot 2021-12-08 at 17 31 25

Screen Shot 2021-12-08 at 17 19 33

Add following brownie-config.yaml file to your project:

compiler:
solc:
version: 0.6.12

When you compile, brownie will download solc version from config.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.