SigmaGmbH / swisstronik-tutorials

This repo provides tutorials/samples for deploying and interacting with contracts. Learn to use Hardhat and SwisstronikJS to confidently use Swisstronik Blockchain.
20 stars 73 forks source link

Error: TypeError: perc20.waitForDeployment is not a function in Hardhat@^2.12.7 #5

Closed warifp closed 1 year ago

warifp commented 1 year ago

when I deploy (npm run deploy) there is an error like this:

npm run deploy

> deploy
> hardhat run scripts/deploy.js

TypeError: perc20.waitForDeployment is not a function

After I checked it turned out there was an error in the hardhat version, in the source code directory "scripts/deploy.js" is a

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

async function main() {
  const perc20 = await ethers.deployContract("PERC20Sample");
  await perc20.waitForDeployment();

  console.log(`PERC20Sample was deployed to ${perc20.address}`);
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

It should be await perc20.waitForDeployment(); replaced with await perc20.deployed();


Conclusion

  1. await perc20.waitForDeployment(); only for hardhat-toolbox@^3.0.0 and hardhat@^2.17.1
  2. for this perc20.deployed(); is with hardhat-toolbox@^1.0.2 and hardhat@^2.12.7

So the correct script is

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

async function main() {
  const perc20 = await ethers.deployContract("PERC20Sample");
  await perc20.deployed();

  console.log(`PERC20Sample was deployed to ${perc20.address}`);
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
warifp commented 1 year ago

Proof

image

SantiagoDevRel commented 1 year ago

Hi @warifp thanks for submitting the issue, we decided to reward you with 50usd & 50usd in SWTR tokens, I'll publish this in the https://github.com/SigmaGmbH/Bug-Bounty-1.0/tree/main/Hall%20Of%20Fame by the end of the day.