Replies: 2 comments
-
Hello @CrypptoPaul Could you please share the contract code here in order to check it? |
Beta Was this translation helpful? Give feedback.
0 replies
-
/ SPDX-License-Identifier: MIT
pragma solidity ^0.6.6;
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol";
contract Lottery is VRFConsumerBase, Ownable {
//to keep track on who signed in for the lottery (array)
address payable[] public players;
address payable public recentWinner;
uint256 public usdEntryFee;
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; //closed
fee = _fee;
keyhash = _keyhash;
}
function enter() public payable {
//50 dolar minium
require(lottery_state == LOTTERY_STATE.OPEN);
require(msg.value >= getEntranceFee(), "Not Enough ETH!");
players.push(msg.sender); //push the enter address to the array
}
function getEntranceFee() public view returns (uint256) {
(, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
uint256 adjustedPrice = uint256(price) * 10**10; //(18 decimals)
//50/2000
uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice;
return costToEnter;
}
function startLottery() public onlyOwner {
require(
lottery_state == LOTTERY_STATE.CLOSED,
"Can't start a new lottery yet!"
); //0
}
function endLottery() public onlyOwner {
//t256(keccack256(
// abi.encodePacked(
// nonce,
// msg.sender,
// block.difficulty,
// block.timestamp
// )
// )
//% players.lenght
lottery_state == LOTTERY_STATE.CALCULATING_WINNER;
bytes32 requestId = requestRandomness(keyhash, fee);
}
//2nd transaction request - receive procedure
//its internal the chainlink node is calling the vrf coordinador, so its only the one that can fullfill it
function fullfillRandomness(bytes32 _requestId, uint256 _randomness)
internal
override
{
require(
lottery_state == LOTTERY_STATE.CALCULATING_WINNER,
"Not 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;
}
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Compiling contracts...
Solc version: 0.6.12
Optimizer: Enabled Runs: 200
EVM Version: Istanbul
CompilerError: solc returned the following errors:
contracts/Lottery.sol:82:9: TypeError: Function has override specified but does not override anything.
override
^------^
contracts/Lottery.sol:10:1: TypeError: Contract "Lottery" should be marked as abstract.
contract Lottery is VRFConsumerBase, Ownable {
^ (Relevant source part starts here and spans across multiple lines).
C:/Users/ppuen/.brownie/packages/smartcontractkit/[email protected]/contracts/src/v0.6/VRFConsumerBase.sol:121:3: Missing implementation:
function fulfillRandomness(bytes32 requestId, uint256 randomness)
^ (Relevant source part starts here and spans across multiple lines).
Any advice or recommendation on how to sort this out is highly appreciated.!!!
Beta Was this translation helpful? Give feedback.
All reactions