Import "@openzeppelin/contracts/access/Ownable.sol"; not found. How to solve it?

Solidity:

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

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

contract Lottery is Ownable {
    address payable[] public players;
    uint256 public usdEntryFee;
    AggregatorV3Interface internal ethUsdPriceFeed;
    enum LOTTERY_STATE {
        OPEN,
        CLOSED,
        CALCULATING_WINNER
    }
    LOTTERY_STATE public lottery_state;
    // OPEN = 0
    //CLOSED = 1
    //CALCULATING_WINNER = 2

    LOTTERY_STATE public lottery_state;

    constructor(address _priceFeedAddress) public {
        usdEntryFee = 50 * (10**18);
        ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
        lottery_state = LOTTERY_STATE.CLOSED; // or "lottery_state = 1;
    }

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

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

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

    function endLottery() public {}
}

brownie-config.yaml:

dependecies:

  • smartcontractgit/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'
      networks:
      mainnet-fork:
      eth_usd_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419'

Hi, welcome to the community! :wave:

Sorry, I am not familiar with the Brownie, maybe you can look the Brownie documentations, it explains this and has examples for OpenZeppelin at the same time:

https://eth-brownie.readthedocs.io/en/stable/package-manager.html#package-manager

1 Like

finally found it :slight_smile: thank u so much