ParserError: Source file requires different compiler version #522
-
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? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 34 replies
-
Hello @gorkemkeles it happens when the also change this:
to this
Finally if you have linting warning you could refer to this apart. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
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"; terminal:
On changing the compiler on version 0.8.0 selected on vscode, but keeping the compiler version on your contract to ^0.6.0,
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:
I really appreciate you trying to help here. |
Beta Was this translation helpful? Give feedback.
-
I reverted back all the changes so now, the code looks as below and the compiler is
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/[email protected]'
- '@openzeppelin=OpenZeppelin/[email protected]'
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
|
Beta Was this translation helpful? Give feedback.
-
Yes i tried that as well, the error changed , now when i compile:
|
Beta Was this translation helpful? Give feedback.
-
Add following brownie-config.yaml file to your project: compiler: When you compile, brownie will download solc version from config. |
Beta Was this translation helpful? Give feedback.
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.