const {ethers} = require("hardhat")

async function main(){
const SimpleStorageFactory =  await ethers.getContractFactory("SimpleStorage")  
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


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



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

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


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


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 that you have read and understand our privacy policy and code of conduct.

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