LESSON 9 => TypeError: Cannot read properties of undefined (reading '0') #5779
-
| const { network, ethers } = require("hardhat")
const {developmentChains, networkConfig} = require("../helper-hardhat-config")
const {verify} = require("../utils/verify")
const VRF_SUB_FUND_AMOUNT = ethers.parseEther("2")
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.getAddress
        const transactionResposne = await vrfCoordinatorV2Mock.createSubscription()
        const transactionReceipt = await transactionResposne.wait(1)
        
        subscriptionId = transactionReceipt.events[0].args.subId
        // we have to fund the subsciption
        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"]
    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) {
        console.log("Verifying")
        await verify(raffle.address, args)
    }
}
module.exports.tags = ["all","raffle"]This is my deploy code for raffle. Probably the error is in this line.  | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            alymurtazamemon
          
      
      
        Jul 2, 2023 
      
    
    Replies: 2 comments 20 replies
-
| @harry2855 You can console log the  | 
Beta Was this translation helpful? Give feedback.
                  
                    16 replies
                  
                
            -
| 
 Hi @harry2855 - did you ever find a solution to the error: TypeError: (0 , ethers_1.getAddress) is not a function? | 
Beta Was this translation helpful? Give feedback.
                  
                    4 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
@harry2855 No this is not an ethers issue, instead the mock contract response was not emitting the event of subscript created. But we can by pass it because we know it is the first subscript so we can do this
And also
addressis know renamed totargetvrfCoordinatorV2Address = vrfCoordinatorV2Mock.target;