I tried all that you mentioned in the discussion here (in other questions) and at https://github.com/smartcontractkit/full-blockchain-solidity-course-py/discussions/522 , however it is not solving the issue for me, I also noticed that the current compiler version remains (current compiler is 0.6.12+commit.27d51765.Windows.msvc). But when I right click and select Solidty:Compiler information, it shows 0.8.0.
from output:
Retrieving compiler information:
Compiler using remote version: 'v0.8.0+commit.c7dfd78e', solidity version: 0.8.0+commit.c7dfd78e.Emscripten.clang
Not sure if that is related to the issue I face. Anyways starting with the problem I see when running brownie compile. I get the error below:
error in 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.2.1/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>
My .sol file 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.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;
}
}
I also tried to google some solutions so my settings.json file is a bit different but that didnt help too.
settings.json:
{
"solidity.compileUsingRemoteVersion": "v0.8.0+commit.c7dfd78e",
"solidity.defaultCompiler": "remote",
"solidity.compileUsingLocalVersion": "d:\\Python projects\\Solidity dev\\demo\\smartcontract-lottery\\soljson-v0.8.0+commit.c7dfd78e.js"
// "solidity.compileUsingRemoteVersion": "v0.7.4+commit.3f05b770",
// "solidity.enableLocalNodeCompiler": false
}
In the brownie-config.yaml, I tried all the versions of openzepplin contracts too from old to latest (4.4.0, 4.3.0,4.3.2 etc), but same error.
brownie-config.yaml
dependencies:
- smartcontractkit/chainlink-brownie-contracts@1.1.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'
I also tried to change the compiler in lottery.sol file with
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
Now I get a different error. Completely lost here :(
terminal:
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:
ParserError: Source file requires different compiler version (current compiler is 0.8.11+commit.d7f03943.Windows.msvc) - note that nightly builds are considered to be strictly less than the released version
--> C:/Users/rosne/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@0.2.1/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol:2:1:
|
2 | pragma solidity ^0.6.0;
| ^^^^^^^^^^^^^^^^^^^^^^^
PS D:\Python projects\Solidity dev\demo\smartcontract-lottery>
I am very new to programing in solidity and this is the first course I am following, I don't want to give up so easily, any help is much appreciated.
I managed to find the issue, it was because the function name should be fullfillRandomness instead of FullfillRandomness. So much problem because of a capital F.
function FulfillRandomness(bytes32 _requestId, uint256 _randomness)
internal
override