PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
117 stars 183 forks source link

Error #192

Closed HUMAYOU-ALI-SARAL closed 9 months ago

HUMAYOU-ALI-SARAL commented 9 months ago

Everything works perfectly as expected, contract is getting deployed on hardhat network as expected but Its not working in sepolia. when I writes

 yarn hh deploy --network sepolia 

its giving this error

TypeError: Cannot read properties of undefined (reading 'length')
    at getFrom (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat-deploy/src/helpers.ts:1640:14)
    at fetchIfDifferent (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat-deploy/src/helpers.ts:827:34)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at _deployOne (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat-deploy/src/helpers.ts:905:24)
    at DeploymentsManager.executeDeployScripts (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1214:19)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at DeploymentsManager.runDeploy (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1060:5)
    at SimpleTaskDefinition.action (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat-deploy/src/index.ts:444:5)
    at Environment._runTaskDefinition (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat/src/internal/core/runtime-environment.ts:358:14)
    at Environment.run (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat/src/internal/core/runtime-environment.ts:191:14)
    at SimpleTaskDefinition.action (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat-deploy/src/index.ts:595:32)
    at Environment._runTaskDefinition (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat/src/internal/core/runtime-environment.ts:358:14)
    at Environment.run (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat/src/internal/core/runtime-environment.ts:191:14)
    at SimpleTaskDefinition.action (/media/humayou/272F73E63EAB4DD6/hardHat/Decentralize Lottery Platform/node_modules/hardhat-deploy/src/index.ts:684:5)

My Deploy File:

const {network, ethers} = require("hardhat") 
const {networkConfig}=require("../helpers-hardhat")
module.exports=async function({ getNamedAccounts, deployments}){
   let vrfCoordinator;
   const{deploy,log}=deployments;
   const {deployer}=await getNamedAccounts()
   const chainId=network.config.chainId
   if(chainId===31337){
     const mock=await ethers.getContract("VRFCoordinatorV2Mock")
     vrfCoordinator=await mock.getAddress()
   }
   else{
      vrfCoordinator=networkConfig[chainId]["vrfCoordinator"]
   }

   const entranceFee=networkConfig[chainId]["entranceFee"]
   const subId=networkConfig[chainId]["subscriptionId"]
   const interval=5;
   const callbackGasLimit=300;
   const gasLane=networkConfig[chainId]["gasLane"]
   const arguments=[entranceFee,vrfCoordinator,gasLane,subId,callbackGasLimit,interval]
   const Lottery=await deploy("Lottery",{
    from:deployer,
    log:true,
    args:arguments,
    waitConfirmation:network.config.blockConfirmations||1, 
   })
   log("------real contract deployed hurray!!!!!!!!!!!!!")
}

config file:

require("@nomiclabs/hardhat-waffle")
require("@nomiclabs/hardhat-ethers")
require("hardhat-deploy")
require("solidity-coverage")
require("hardhat-gas-reporter")
require("hardhat-contract-sizer")
require("dotenv").config()

const PrivateKey=process.env.PrivateKey
const EtherScanApiKey=process.env.EtherScanApiKey
const Sepolia_Rpc_Url=process.env.Sepolia_Rpc_Url
/** 
 * 
@type import('hardhat/config').HardhatUserConfig 
*/

module.exports={
  defaultNetwork:"hardhat",
  solidity:"0.8.18",
  namedAccounts: {
    // default:0,
        deployer: {
            default: 0, 
            1:0// here this will by default take the first account as deployer
             // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another
        },
        player: {
            default: 0,
        },
    },
  networks:{
    hardhat:{
      chainId:31337,
      blockConfirmation:1,
    },
    sepolia:{
      chainId:11155111,
      blockConfirmation:6,
      url:Sepolia_Rpc_Url||"https://eth-sepolia.g.alchemy.com/v2/ElyVvZi045_6qUvVtN4HagaSbIfr0WQx",
      account:PrivateKey!==undefined?[PrivateKey]:[]
    }
  }
}

somebody help me please, I have got stucked from last two day, its getting insane