0

Error:

PS D:\SimpleStorage> npx hardhat run scripts/deploy.js
TypeError: chai.deployed is not a function
    at main (D:\SimpleStorage\scripts\deploy.js:11:16)
PS D:\SimpleStorage> 

deploy.js:

const hre = require("hardhat");

async function main() {
    // Fetching the byte code and ABI
    const Chai = await hre.ethers.getContractFactory("chai");

    // Deploying an instance of our smart contract
    const chai = await Chai.deploy();

    // Waiting for the contract to be deployed
    await chai.deployed();

    console.log("Deployed contract address:", chai.address);
}

main()
    .then(() => process.exit(0))
    .catch((error) => {
        console.error(error);
        process.exit(1);
    });

hardhat.config.js:

require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.24",
};

1 Answer 1

0

You should use waitForDeployment() instead of deployed(), because deployed() is replaced with waitForDeployment() in the newer versions of Hardhat.

Also, you need to replace chai.address with await chai.getAddress().

So, in your deploy.js file, replace:

// Waiting for the contract to be deployed
await chai.deployed();

console.log("Deployed contract address:", chai.address);

with:

// Waiting for the contract to be deployed
await chai.waitForDeployment();

console.log("Deployed contract address:", await chai.getAddress());

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.