smartcontractkit / full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
11.94k stars 2.89k forks source link

simpleStorage.deployed is not a function #6104

Open FlySkyler opened 10 months ago

FlySkyler commented 10 months ago

Lesson

Lesson 6

Could you please leave a link to the timestamp in the video where this error occurs? (You can right click a video and "copy video URL at current time")

https://www.youtube.com/watch?v=gyMwXuJrbJQ&list=PL4sBgjGsKcGAMfrkGoOwglLKlc4-jCTK6&index=1&t=30935s

Operating System

Windows

Describe the bug

typeError : .deployed() is not a function

when i try to run my scripts with the command "yarn hardhat run scripts/deploy.js" it says that "simpleStorage.deployed is not a function"

here's my code :

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

async function main() {
  const SimpleStorageFactory = await ethers.getContractFactory(
    "SimpleStorage"
    );
    console.log("deploying contract...");
    const simpleStorage = await SimpleStorageFactory.deploy();
    await simpleStorage.deployed();
    console.log(`deployted contract to : ${simpleStorage.address}`);
}

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

and here's my package.json

{
  "name": "hardhatproject",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
    "@nomicfoundation/hardhat-ethers": "^3.0.0",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.0",
    "@nomicfoundation/hardhat-toolbox": "^3.0.0",
    "@nomicfoundation/hardhat-verify": "^1.0.0",
    "@typechain/ethers-v6": "^0.4.0",
    "@typechain/hardhat": "^8.0.0",
    "chai": "^4.2.0",
    "ethers": "^6.4.0",
    "hardhat": "^2.17.2",
    "hardhat-gas-reporter": "^1.0.8",
    "prettier": "^3.0.3",
    "prettier-plugin-solidity": "^1.1.3",
    "solidity-coverage": "^0.8.0",
    "typechain": "^8.1.0"
  }
}

hope someone can help me :

heheboii11 commented 10 months ago

no need of await simplestorage.deployed() just run without adding this it will run fine. And if you want to wait for block conformation use simplestorage.deployTransaction.wait(6) like that

FlySkyler commented 10 months ago

no need of await simplestorage.deployed() just run without adding this it will run fine. And if you want to wait for block conformation use simplestorage.deployTransaction.wait(6) like that thank you it worked !

Yazep commented 7 months ago

You need to wait in order to get address later. What you can do just change 2 funstions. "deployed()" to "waitForDeployment()" and "address" to "target"

 await simpleStorage.waitForDeployment(); // Wait for the contract deployment to complete
  console.log(`Contract deployed to address: ${simpleStorage.target}`);