PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
118 stars 182 forks source link

Can someone explain this error please? #109

Closed Adnanebds closed 2 years ago

Adnanebds commented 2 years ago

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, })

if (!developmentChains.includes(network.name && process.env.ETHERSCAN_API_KEY)) {
    log("Verifying...")
    await verify(raffle.address, args)
}
log("---------------------------------")

}

module.exports.tags = ["all", "raffle"]

ade-hardhat commented 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.

Adnanebds commented 2 years ago

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

PatrickAlphaC commented 2 years ago

Can you:

  1. Make this a discusson on the full repo? https://github.com/smartcontractkit/full-blockchain-solidity-course-js/
  2. Follow this section for formatting questions? https://www.youtube.com/watch?t=19846&v=gyMwXuJrbJQ&feature=youtu.be