[英]Solidity: Abstract contract and override VRFConsumerBase compiler/version/import issues
[英]solidity : error information Source file requires different compiler version
在编译lottery.sol的时候遇到了这个编译错误,作为一个开发菜鸟,对这个错误不是很理解,请问这个编译版本问题有什么办法解决,真是郁闷。。。
Compiling contracts...
Solc version: 0.6.12
Optimizer: Enabled Runs: 200
EVM Version: Istanbul
CompilerError: solc returned the following errors:
/Users/liwei/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@1.1.1/contracts/src/v0.6/vendor/SafeMathChainlink.sol:2:1: ParserError: Source file requires different compiler version (current compiler is 0.6.12+commit.27d51765.Darwin.appleclang) - note that nightly builds are considered to be strictly less than the released version
pragma solidity >=0.7.0 <0.9.0;
彩票.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";
import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";
contract Lottery is VRFConsumerBase, Ownable {
AggregatorV3Interface internal ethUsdPriceFeed;
uint256 usdEntryFee;
address[] public players;
bytes32 internal keyHash; //public key to generate randomness,uniquely identify the chainlink node.
uint256 internal fee;
uint256 public randomness;
enum LOTTERY_STATE {
OPEN,
CLOSED,
CALCULATING_WINNER
}
LOTTERY_STATE public lottery_state;
constructor(
address _priceFeedAddress,
address _VRFCoordinator, //contract to validate the random number
address _link, //address to pay oracle gas
uint256 _fee,
bytes32 _keyhash
) public VRFConsumerBase(_vrfCoordinator, _link) {
usdEntryFee = 50 * (10**18);
ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
lottery_state = CLOSED;
fee = _fee;
keyhash = _keyhash;
}
function enter() public payable {
require(lottery_state == OPEN);
// require amount>=entrance fee ($50 in Ether)
require(msg.value >= getEntranceFee(), "Not enought ETH!");
// push player's address into the the array
players.push(msg.sender);
}
function getEntranceFee() public view returns (uint256) {
(, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
uint256 adjustedPrice = uint256(price) * (10**10); // 18 decimals
// $50,$2,000 / ETH
// 50/2,000
// 50 *100000 / 20000
uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice; //usdEntryFee has additional 18 decimals
return costToEnter;
}
function startLottery() public {
require(lottery_state == CLOSED, "Can't start a new lottery yet");
lottery_state = LOTTERY_STATE.OPEN;
}
function endLottery() public {
lottery_state = LOTTERY_STATE.CLOSED;
require(
LINK.balanceOf(address(this)) >= fee,
"Not enough LINK - fill contract with faucet"
);
bytes32 requestId = requestRandomness(keyHash, fee); // make the inital request for randomness
}
function fulfillRandomness(bytes32 _requestId, uint256 _randomness)
internal
override
{
require(
lottery_state == LOTTERY_STATE.CALCULATING_WINNER,
"You are n't there yet !"
);
require(_randomness > 0, "radnom-not-found !");
uint256 indexOfWinner = _radonmness % players.length; // get the remainder,Modulo pattern
recentWinner = players[indexOfWinner];
rencentWinner.tranfer(address(this).balance);
// reset the players array
players = new address payable[](0);
lottery_state = LOTTERY_STATE.CLOSED;
randomness = _randomness;
}
}
按照错误信息提示更改编译器版本后,提示将编译器版本切换回来。
New compatible solc version available: 0.8.11
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.Darwin.appleclang) - note that nightly builds are considered to be strictly less than the released version
--> /Users/liwei/.brownie/packages/OpenZeppelin/openzeppelin-contracts@3.4.0/contracts/access/Ownable.sol:3:1:
|
3 | pragma solidity >=0.6.0 <0.8.0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ParserError: Source file requires different compiler version (current compiler is 0.8.11+commit.d7f03943.Darwin.appleclang) - note that nightly builds are considered to be strictly less than the released version
--> /Users/liwei/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@1.1.1/contracts/src/v0.6/VRFConsumerBase.sol:2:1:
|
2 | pragma solidity ^0.6.0;
| ^^^^^^^^^^^^^^^^^^^^^^^
(base) liwei@liweideMacBook-Pro smartcontract-lottery2022 %
它指出SafeMathChainlink.sol
使用了另一个编译器版本,该版本与您正在使用的版本不兼容。
所以这里有一些你可以尝试的东西:
0.6.x
而不是0.7-0.9
的SafeMathChainlink.sol
。0.7.x
并查找符合0.7.x
VRFConsumerBase.sol
可能类似于: @chainlink/contracts/src/v0.6/VRFConsumerBase.sol
)VRFConsumerBase.sol
或VRFConsumerBase.sol
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.