-
While deploying rafale im getting this error.. 01-deploy-raffle.js const { network, ethers } = require("hardhat")
const { developmentChains, networkConfig, } = require("../helper-hardhat-config")
const {verify} = require("../utils/verify")
const VRF_SUB_FUND_AMOUNT = ethers.utils.parseEther("0.1")
module.exports = async function ({ getNamedAccounts, deployments }) {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
let vrfCoordinatorV2Address, subscriptionId
if (developmentChains.includes(network.name)) {
const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
const transactionReceipt = await transactionResponse.wait(1)
subscriptionId = transactionReceipt.events[0].args.subId
//fund the subscription
//usually you need the link token on a real network
await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VRF_SUB_FUND_AMOUNT)
} else {
vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"]
subscriptionId = networkConfig[chainId]["subscriptionId"]
}
const entranceFee = networkConfig[chainId]["entranceFee"]
const gasLane = networkConfig[chainId]["gasLane"]
const callBackGasLimit = networkConfig[chainId]["callBackGasLimit"]
const interval = networkConfig[chainId]["interval"]
const args = [
vrfCoordinatorV2Address,
entranceFee,
gasLane,
subscriptionId,
callBackGasLimit,
interval,
]
const raffle = await deploy("Raffle", {
from: deployer,
args: args,
logs: true,
waitConfirmations: network.config.blockConfirmations || 1,
})
if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
log("Verifying...")
await verify(raffle.address, args)
}
log("-----------------------------------------------------------")
}
module.exports.tags = ["all", "raffle"] Raffle.sol // SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/interfaces/KeeperCompatibleInterface.sol";
error Raffle__NotEnoughEthEnterd();
error Raffle__TransferFailed();
error Raffle__NotOpen();
error Raffle__UpkeepNotNeeded(uint256 currentBalance, uint256 numPlayers, uint256 raffleState);
/**@title sample raffle contract
* @author yash dhumal
* @notice this contract is for creating an untamperable decentralized smart contract
* @dev this implements chinlink keepers and chainlink vrf v2
*/
abstract contract Raffle is VRFConsumerBaseV2, KeeperCompatibleInterface{
//type declarations
enum RaffleState {
OPEN,
CALCULATING
}
//State Variables
uint256 private immutable i_entranceFee;
address payable[] private s_players;
VRFCoordinatorV2Interface private immutable i_vrfCoordinator;
bytes32 private immutable i_gasLane;
uint64 private immutable i_subscriptionId;
uint32 private immutable i_callbackGasLimit;
uint32 private immutable NUM_WORDS = 1;
uint16 private constant REQUEST_CONFIRMATIONS = 3;
//Lottery Variables
address private s_recentWinner;
RaffleState private s_raffleState;
uint256 private s_lastTimeStamp;
uint256 private immutable i_interval;
//events
event RaffleEnter(address indexed player);
event RequestedFaffleWinner(uint256 indexed requestId);
event WinnerPicked(address indexed winner);
constructor(
address vrfCordinatorV2,
uint256 entranceFee,
bytes32 gasLane,
uint64 subscriptionId,
uint32 callbackGasLimit,
uint256 interval
) VRFConsumerBaseV2(vrfCordinatorV2) {
i_entranceFee = entranceFee;
i_vrfCoordinator = VRFCoordinatorV2Interface(vrfCordinatorV2);
i_gasLane = gasLane;
i_subscriptionId = subscriptionId;
i_callbackGasLimit = callbackGasLimit;
s_raffleState = RaffleState.OPEN;
s_lastTimeStamp = block.timestamp;
i_interval = interval;
}
function enterRaffle() public payable{
if(msg.value < i_entranceFee){
revert Raffle__NotEnoughEthEnterd();
}
if(s_raffleState != RaffleState.OPEN){
revert Raffle__NotOpen();
}
s_players.push(payable(msg.sender));
//emit an event when we update a dynamic array or mapping
//named events with funciton name reversed
emit RaffleEnter(msg.sender);
}
/**
* @dev this is the function that the chainlink keeper nodes call they look for the `upkeepNeeded` to return true
* following should be true in order to return true:
* 1.Our time interval should have passed
* 2.Lottery should have at least 1 player and should have some eth
* 3.Then our subscription is funded with LINK
* 4.Lottery should be in open state
*/
function checkUpkeep(bytes memory /*checkData*/) public override returns(bool upkeepNeeded, bytes memory /*performData*/) {
bool isOpen = (RaffleState.OPEN == s_raffleState);
bool timePassed = ((block.timestamp - s_lastTimeStamp) > i_interval);
bool hasPlayers = (s_players.length > 0);
bool hasBalance = address(this).balance > 0;
upkeepNeeded = (isOpen && timePassed && hasBalance && hasPlayers);
}
function performUpkeep(bytes calldata /*performData*/) external override{
(bool upkeepNeeded, ) = checkUpkeep('');
if(!upkeepNeeded){
revert Raffle__UpkeepNotNeeded(address(this).balance,s_players.length, uint256(s_raffleState));
}
s_raffleState = RaffleState.CALCULATING;
uint256 requestId = i_vrfCoordinator.requestRandomWords(
i_gasLane, //gas lane
i_subscriptionId,
REQUEST_CONFIRMATIONS,
i_callbackGasLimit,
NUM_WORDS
);
emit RequestedFaffleWinner(requestId);
}
function fulfillRandomWor(uint256 /*requestId*/, uint256[] memory randomWords) internal /*override */{
uint256 indexOfWinner = randomWords[0] % s_players.length;
address payable recentWinner = s_players[indexOfWinner];
s_recentWinner = recentWinner;
s_raffleState = RaffleState.OPEN;
s_players = new address payable[](0);
s_lastTimeStamp = block.timestamp;
(bool success, ) = recentWinner.call{value: address(this).balance}("");
if(!success){
revert Raffle__TransferFailed();
}
emit WinnerPicked(recentWinner);
}
function getEntranceFee() public view returns(uint256){
return i_entranceFee;
}
function getPlayer(uint256 index) public view returns(address){
return s_players[index];
}
function getRecentWinner() public view returns(address){
return s_recentWinner;
}
function getRaffleState() public view returns(RaffleState){
return s_raffleState;
}
function getNumWords() public pure returns(uint256){
return NUM_WORDS;
}
function getNuumberOfPlayers() public view returns(uint256){
return s_players.length;
}
function getLatestTimeStamp() public view returns(uint256){
return s_lastTimeStamp;
}
function getRequestConfirmations() public pure returns(uint256){
return REQUEST_CONFIRMATIONS;
}
}
|
Beta Was this translation helpful? Give feedback.
Answered by
krakxn
Aug 14, 2022
Replies: 1 comment 13 replies
-
Fix the typos above |
Beta Was this translation helpful? Give feedback.
13 replies
Answer selected by
yash-2138
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fix the typos above