Lesson 7 - Lottery Constructor error on compile #947
-
|
Hi, Here is my code Lottery.sol // SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.0 <0.9.0;
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
contract Lottery {
address payable[] public players;
uint256 public usdEntryFee;
AggregatorV3Interface internal ethUsdPriceFeed;
enum LOTTERY_STATE {
OPEN,
CLOSED,
SELECTING_WINNER
}
LOTTERY_STATE public lottery_state;
constructor(address _priceFeedAddress) public {
usdEntryFee = 50 * (10**18);
ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
lottery_state = LOTTERY_STATE.CLOSED;
}
function enter() public payable {
// $50 entrance
require(
msg.value >= getEntranceFee(),
"Not enough Eth to meet min Entry 50 usd"
);
players.push(msg.sender);
}
function getEntranceFee() public view returns (uint256) {
(, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
uint256 adjustedPrice = uint256(price) * 10**10; // 18 decimals
uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice;
return costToEnter;
}
function startLot() public {}
function endLot() public {}
}
and the brownie-config.yaml dependencies:
- smartcontractkit/chainlink-brownie-contracts@1.1.1
compiler:
solc:
remappings: "@chainlink=smartcontractkit/chainlink-brownie-contracts@1.1.1"
networks:
mainnet-fork:
eth_usd_price_feed: "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419"
This is the full error message: Hope you can spot my error, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
You need to convert Update your function enter() public payable {
require(lottery_state == LOTTERY_STATE.OPEN);
require(msg.value >= getEntranceFee(), "Not enough ETH!");
players.push(payable(msg.sender));
} |
Beta Was this translation helpful? Give feedback.
-
|
Hello @Dave777. first of all you can remove the constructor(address _priceFeedAddress) public {
usdEntryFee = 50 * (10**18);
ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
lottery_state = LOTTERY_STATE.CLOSED;
}And @freddie71010 is right, in solidity v 0.8.0 the directions are not automatically payable, so you can use his solution, also you can refer here for more information. |
Beta Was this translation helpful? Give feedback.
You need to convert
msg.senderto apayableaddress since you cannot add a non-payable address to an array.Update your
enter()function to includeplayers.push(payable(msg.sender));