2
const {ethers} = require("hardhat")

async function main(){
const SimpleStorageFactory =  await ethers.getContractFactory("SimpleStorage")  
console.log("Deploying,....")
const simpleStorage= SimpleStorageFactory.deploy()
await (await simpleStorage).deployed()
}

On this function , I am running into an error:

TypeError: Cannot read properties of undefined (reading 'getContractFactory')

Can someone tell me what's going on?

4 Answers 4

1

It's complaining that ethers is not defined, check your package.json to see if you correct installed hardhat-ethers plugin.

https://github.com/NomicFoundation/hardhat/tree/master/packages/hardhat-ethers

1

On the last line, I see two "await" which is not correct I think. I would create deploy script like this:

const hre = require("hardhat");

async function main() {
  const SimpleStorage = await hre.ethers.getContractFactory("SimpleStorage")  
  const simpleStorage= await SimpleStorage.deploy();
  await simpleStorage.deployed();
  console.log(`simple storage deployed: ${simpleStorage.address}` )
}
1

Add the following code snippet at the top of your hardhat.config.js file

    require("@nomiclabs/hardhat-waffle");

solution from here: https://stackoverflow.com/questions/70628980/typeerror-cannot-read-properties-of-undefined-reading-getcontractfactory-wh

0

presuming the simple storage contract doesn't require any deploy time arguments

try this

const simpleStorageFactory =  await ethers.getContractFactory("SimpleStorage") 
const simpleStorage = await simpleStorageFactory.deploy()
await simpleStorage.deployed()

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.