Closed Adnanebds closed 2 years ago
Hi, make sure that your arguments for the deploy script is lined up in the same order as the parameters in your contract's constructor.
const args = [
vrfCoordinatorV2Address,
entranceFee,
interval,
gasLane,
callbackGasLimit,
subscriptionId,
]
constructor(
address vrfCoordinatorV2, //contract, we're going to need to deploy mocks for this
uint256 entranceFee,
bytes32 gasLane,
uint64 subscriptionId,
uint256 callbackGasLimit,
uint256 interval
)
For example, the above isn't lined up in the same order. Correct order would be :
const args = [
vrfCoordinatorV2Address,
entranceFee,
gasLane,
subscriptionId,
callbackGasLimit,
interval
]
I hope this helps.
Now i get the error: unexpected error occurred:
Error: ERROR processing /home/kenkitano/hardhat-tutorial/deploy/01-deploy-raffle.js: Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.7.0)
CODE (js):
const { network, ethers } = require("hardhat") const { developmentChains, networkConfig } = require("../helper-hardhat-config") const { verify } = require("../helper-hardhat-config") const VRF_SUB_FUND_AMOUNT = ethers.utils.parseEther("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)) { vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock") vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address const transactionResponse = await vrfCoordinatorV2Mock.createSubscription() const transactionReceipt = await transactionResponse.wait() subscriptionId = transactionReceipt.events[0].args.subId await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VRF_SUB_FUND_AMOUNT) } else { vrfCoordinatorV2Address = networkConfig[chainId]["VRFCoordinatorV2Mock"] subscriptionId = networkConfig[chainId]["subscriptionId"] } const interval = networkConfig[chainId]["interval"] const callbackGasLimit = networkConfig[chainId]["callbackGasLimit"] const gasLane = networkConfig[chainId]["gasLane"] const entranceFee = networkConfig[chainId]["entranceFee"] const args = [ vrfCoordinatorV2Address, entranceFee, gasLane, subscriptionId, callbackGasLimit, interval, ] const raffle = await deploy("Raffle", { from: deployer, args: args, log: 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"]
CONTRACT:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol"; import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol"; import "@chainlink/contracts/src/v0.8/interfaces/KeeperCompatibleInterface.sol"; import "hardhat/console.sol";
/ Errors / error RaffleUpkeepNotNeeded(uint256 currentBalance, uint256 numPlayers, uint256 raffleState); error RaffleTransferFailed(); error RaffleSendMoreToEnterRaffle(); error RaffleRaffleNotOpen();
/**@title A sample Raffle Contract
@dev This implements the Chainlink VRF Version 2 / contract Raffle is VRFConsumerBaseV2, KeeperCompatibleInterface { / Type declarations / enum RaffleState { OPEN, CALCULATING } / State variables */ // Chainlink VRF Variables VRFCoordinatorV2Interface private immutable i_vrfCoordinator; uint64 private immutable i_subscriptionId; bytes32 private immutable i_gasLane; uint32 private immutable i_callbackGasLimit; uint16 private constant REQUEST_CONFIRMATIONS = 3; uint32 private constant NUM_WORDS = 1;
// Lottery Variables uint256 private immutable i_interval; uint256 private immutable i_entranceFee; uint256 private s_lastTimeStamp; address private s_recentWinner; address payable[] private s_players; RaffleState private s_raffleState;
/ Events / event RequestedRaffleWinner(uint256 indexed requestId); event RaffleEnter(address indexed player); event WinnerPicked(address indexed player);
/ Functions / constructor( address vrfCoordinatorV2, //contract, we're going to need to deploy mocks for this uint256 entranceFee, bytes32 gasLane, uint64 subscriptionId, uint32 callbackGasLimit, uint256 interval ) VRFConsumerBaseV2(vrfCoordinatorV2) { i_vrfCoordinator = VRFCoordinatorV2Interface(vrfCoordinatorV2); i_gasLane = gasLane; i_interval = interval; i_subscriptionId = subscriptionId; i_entranceFee = entranceFee; s_raffleState = RaffleState.OPEN; s_lastTimeStamp = block.timestamp; i_callbackGasLimit = callbackGasLimit; }
function enterRaffle() public payable { // require(msg.value >= i_entranceFee, "Not enough value sent"); // require(s_raffleState == RaffleState.OPEN, "Raffle is not open"); if (msg.value < i_entranceFee) { revert Raffle__SendMoreToEnterRaffle(); } if (s_raffleState != RaffleState.OPEN) { revert Raffle__RaffleNotOpen(); } s_players.push(payable(msg.sender)); // Emit an event when we update a dynamic array or mapping // Named events with the function name reversed emit RaffleEnter(msg.sender); }
/**
upkeepNeeded
to return True./**
checkUpkeep
is returning true
, this function is called/**
/* Getter Functions /
function getRaffleState() public view returns (RaffleState) { return s_raffleState; }
function getNumWords() public pure returns (uint256) { return NUM_WORDS; }
function getRequestConfirmations() public pure returns (uint256) { return REQUEST_CONFIRMATIONS; }
function getRecentWinner() public view returns (address) { return s_recentWinner; }
function getPlayer(uint256 index) public view returns (address) { return s_players[index]; }
function getLastTimeStamp() public view returns (uint256) { return s_lastTimeStamp; }
function getInterval() public view returns (uint256) { return i_interval; }
function getEntranceFee() public view returns (uint256) { return i_entranceFee; }
function getNumberOfPlayers() public view returns (uint256) { return s_players.length; } }
Can you:
Error: ERROR processing /home/kenkitano/hardhat-tutorial/deploy/01-deploy-raffle.js: TypeError: Cannot read properties of undefined (reading 'toHexString')
const { network, ethers } = require("hardhat") const { developmentChains, networkConfig } = require("../helper-hardhat-config") const { verify } = require("../helper-hardhat-config") const VRF_SUB_FUND_AMOUNT = ethers.utils.parseEther("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)) { vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock") vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address const transactionResponse = await vrfCoordinatorV2Mock.createSubscription() const transactionReceipt = await transactionResponse.wait() subscriptionId = transactionReceipt.events[0].args.subId await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VRF_SUB_FUND_AMOUNT) } else { vrfCoordinatorV2Address = networkConfig[chainId]["VRFCoordinatorV2Mock"] subscriptionId = networkConfig[chainId]["subscriptionId"] } const interval = networkConfig[chainId]["interval"] const callbackGasLimit = networkConfig[chainId]["callbackGasLimit"] const gasLane = networkConfig[chainId]["gasLane"] const entranceFee = networkConfig[chainId]["entranceFee"] const args = [ vrfCoordinatorV2Address, entranceFee, interval, gasLane, callbackGasLimit, subscriptionId, ] const raffle = await deploy("Raffle", { from: deployer, args: args, log: true, waitConfirmations: network.config.blockConfirmations || 1, })
}
module.exports.tags = ["all", "raffle"]