0
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("30")


module.exports = async function ({ getNamedAccounts, deployments }) {
  const { deploy, log } = deployments
  const deployer = 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
    await VRFCoordinatorV2Mock.fundSubscription(
      subscriptionId,
      VRF_SUB_FUND_AMOUNT
    )
  } else {
    vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorv2"]
    subscriptionId = networkConfig[chainId]["subscriptionId"]
  }


  const enterenceFee = networkConfig[chainId]["enterenceFee"]
  const gasLane = networkConfig[chainId]["gasLane"]
  const callbackGasLimit = networkConfig[chainId]["callbackGasLimit"]
  const interval = networkConfig[chainId]["interval"]

  const arguments = [
    vrfCoordinatorV2Address,
    enterenceFee,
    gasLane,
    subscriptionId,
    callbackGasLimit,
    interval,
  ]
  console.log(deployer)

  const lottery = await deploy("Lottery", {
    from: deployer,
    args: arguments,
    log: true,
    waitConformations: network.config.blockConformations || 1,
  })

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

  log("-----------------------------------")
}


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

An unexpected error occurred:

Error: ERROR processing C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\deploy\01-deploy-lottery.js:
TypeError: from.toLowerCase is not a function
    at getFrom (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat-deploy\src\helpers.ts:1740:34)
    at _deploy (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat-deploy\src\helpers.ts:534:9)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at runNextTicks (node:internal/process/task_queues:65:3)
    at listOnTimeout (node:internal/timers:528:9)
    at processTimers (node:internal/timers:502:7)
    at _deployOne (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat-deploy\src\helpers.ts:1005:16)       
    at Object.module.exports [as func] (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\deploy\01-deploy-lottery.js:50:19)   
    at DeploymentsManager.executeDeployScripts (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1219:22)
    at DeploymentsManager.runDeploy (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1052:5)
    at DeploymentsManager.executeDeployScripts (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5

Can someone help me out with this.. I am having no idea what mistake I am making.

2 Answers 2

1

Instead of deploying your contract like this:

const lottery = await deploy("Lottery", {
  from: deployer,
  args: arguments,
  log: true,
  waitConformations: network.config.blockConformations || 1,
})

try deploying it like this:

const Lottery = await ethers.getContractFactory("Lottery")
const lottery = await Lottery.deploy(
  vrfCoordinatorV2Address,
  entranceFee,
  gasLane,
  subscriptionId,
  callbackGasLimit,
  interval
)

I had the same issue and this solved it. Newer versions of hardhat recommend it this way, check the docks.

1
  • New method is okay! but old should also work. And at this point, error was not due to old method of deploying contract, it was due to a simple mistake in my hardhat.config.js file in which I didn't defined deployer and in deployer script I am using it.
    – Yana Gupta
    Commented Mar 14, 2023 at 14:44
1

Error is coming b'caz your deployer account is not defined in hardhat.config.js. Define it, then deploy the script once again, then it should not come.

Check the first line of code it is saying from.toLowerCase() is not defined and from the address of deployer. That actually means that deployer is not defined.

Define all the private keys and deployer accounts properly then it should not come. You can take reference from below code:

networks: {
    hardhat: {
      chainId: 31337,
      blockConformations: 1,
      allowUnlimitedContractSize: true
    },
    goerli: {
      url: process.env.GOERLI_RPC_URL,
      accounts: [ process.env.PRIVATE_KEY1, process.env.PRIVATE_KEY2],
      chainId: 5,
      allowUnlimitedContractSize: true,
      blockConformations: 5,
      gas: 5000000,
      gasPrice: 50000000000, 
      allowUnlimitedContractSize: true
    },
  },
  namedAccounts: {
    deployer: {
      default: 0,
      1: 0,
    },
    player: {
      default: 1,
    },
  },

Or from github repo: https://github.com/Yana-Gupta/hardhat-lottery/blob/main/hardhat.config.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.