I am a beginner working on brownie using vscode related to a lottery smart contract. Please don't mind if I am doing any rookie mistakes I am still trying my best to understand it as much as I can :) PROBLEM : The solidity compiler is set to remote and its version is 0.6.6 and even though the required solidity version in the source file is ^0.4.11 I am unable to get past the compilation and if I try to run brownie run scripts/deployLottery.py
I am presented with the same error.
The .sol file is
//SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol";
contract Lottery is VRFConsumerBase {
enum LOTTERY_STATE {
OPEN,
CLOSED,
GET_WINNER
}
address private owner;
address public winner;
address payable[] public contestents;
uint256 public fee;
uint256 public usdEntryFee;
bytes32 public requestID;
bytes32 public keyHash;
LOTTERY_STATE public ls;
AggregatorV3Interface internal priceFeed;
modifier onlyOwner() {
_;
require(msg.sender == owner, "You are not the owner!");
_;
}
constructor(
address _priceFeed,
address _vrfCoordinator,
address _link,
uint256 _fee,
bytes32 _keyHash
) public VRFConsumerBase(_vrfCoordinator, _link) {
usdEntryFee = 50 * (10**18);
priceFeed = AggregatorV3Interface(_priceFeed);
ls = LOTTERY_STATE.CLOSED;
fee = _fee;
keyHash = _keyHash;
owner = msg.sender;
}
function get_ethUsdPrice() private view returns (uint256) {
(, int256 answer, , , ) = priceFeed.latestRoundData();
return uint256(answer);
}
function getEntranceFee() private view returns (uint256) {
uint256 answer = get_ethUsdPrice();
uint256 adjustedPrice = answer * (10**10);
uint256 costToEnter = (usdEntryFee * (10**18)) / adjustedPrice;
return costToEnter;
}
function startLottery() public onlyOwner {
require(
ls == LOTTERY_STATE.CLOSED,
"Can't start another lottery before the previous one finishes!!"
);
ls = LOTTERY_STATE.OPEN;
}
function enterLottery() public payable {
require(
ls == LOTTERY_STATE.OPEN,
"Lottery is unavailable/terminated. Try again later."
);
require(
msg.value >= getEntranceFee(),
"You need to send $50 Worth of eth!!"
);
contestents.push(msg.sender);
}
function endLottery() public onlyOwner {
require(ls == LOTTERY_STATE.OPEN, "The lottery is yet to start!!");
ls = LOTTERY_STATE.GET_WINNER;
requestID = requestRandomness(keyHash, fee);
}
function fulfillRandomness(bytes32 _requestId, uint256 _randomness)
internal
override
{
require(_requestId == requestID, "The Request IDs Don't Match!");
require(ls == LOTTERY_STATE.GET_WINNER, "Can't Procceed!!");
require(_randomness > 0, "Random Not Found!!!");
uint256 winnerAdd = _randomness % contestents.length;
winner = contestents[winnerAdd];
payable(winner).transfer(address(this).balance);
contestents = new address payable[](0);
ls = LOTTERY_STATE.CLOSED;
}
}
When I run brownie compile
in the same folder it gives me
Brownie v1.17.2 - Python development framework for Ethereum
Compiling contracts...
Solc version: 0.6.6
Optimizer: Enabled Runs: 200
EVM Version: Istanbul
CompilerError: solc returned the following errors:
/home/botvenom/.brownie/packages/smartcontractkit/[email protected]/contracts/src/v0.4/ERC677Token.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.6.6+commit.6c089d02.Linux.g++ - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.11;
^----------------------^
/home/botvenom/.brownie/packages/smartcontractkit/[email protected]/contracts/src/v0.4/vendor/StandardToken.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.6.6+commit.6c089d02.Linux.g++ - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.11;
^----------------------^
In the config file
dependencies:
- smartcontractkit/[email protected]
compiler:
solc:
remappings:
- '@chainlink=smartcontractkit/[email protected]'
Which are set to the following in the settings.json
{
"python.defaultInterpreterPath": "/bin/python",
"solidity.compileUsingRemoteVersion": "v0.6.6",
"editor.formatOnSave": true,
"python.formatting.provider": "black",
"bracketPairColorizer.depreciation-notice": false,
"solidity.remappings": [
"@chainlink/=/home/botvenom/.brownie/packages/smartcontractkit/[email protected]",
"@openzeppelin/=/home/botvenom/.brownie/packages/OpenZeppelin/[email protected]"
]
}
This is the compiler details from the Lottery.json file
"compiler": {
"evm_version": "istanbul",
"optimizer": {
"enabled": true,
"runs": 200
},
"version": "0.6.6+commit.6c089d02"
},
I tried to change the original pragma to pragma solidity >=0.4.11;
in both the source files but it is leading to more errors like these to name a few
Compiling contracts...
Solc version: 0.6.6
Optimizer: Enabled Runs: 200
EVM Version: Istanbul
CompilerError: solc returned the following errors:
/home/botvenom/.brownie/packages/smartcontractkit/[email protected]/contracts/src/v0.4/vendor/StandardToken.sol:56:56: ParserError: The state mutability modifier "constant" was removed in version 0.5.0. Use "view" or "pure" instead.
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
^------^
/home/botvenom/.brownie/packages/smartcontractkit/[email protected]/contracts/src/v0.4/interfaces/ERC677.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.6.6+commit.6c089d02.Linux.g++ - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.8;
^---------------------^
Just to add at last, I copy pasted the exact code on Remix IDE too and there it is compiling successfully with no errors. I have been so confused about what to do, any help is appreciated. Thank you!