admin管理员组

文章数量:1297014

I'm coding an NFT minting page named astro-mint. And i'm at this point where I have to deploy my contract through hardhat.

But when i run this mand

npx hardhat run scripts/deploy.js --network dexitTestnet

I get this error

TypeError: AstroMint.deploy is not a function
    at main (/home/astrodude/dxt/astro-mint/scripts/deploy.js:16:39)
    at Object.<anonymous> (/home/astrodude/dxt/astro-mint/scripts/deploy.js:25:1)
    at Module._pile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47

This is how my deploy.js looks like

const hardhat = require("hardhat");
const { MerkleTree } = require('merkletreejs');
const keccak256 = require('keccak256');
const whiteList = require('../utils/whitelist');

const BASE_URI = 'ipfs://Qmb5A1fFECM2iFHgUioii2khT814nCi6VU9aHXHHqNxHCK/';
const proxyRegistryAddress = '0xf57b2c51ded3a29e6891aba85459d600256cf317';


async function main() {
    const leadNodes = whiteList.map(address => keccak256(address));
    const merkleTree = new MerkleTree(leadNodes, keccak256, { sortPairs : true });
    const root = merkleTree.getRoot();
    
    const AstroMint = hardhat.ethers.getContractFactory('AstroMint');
    const astroMint = await AstroMint.deploy(BASE_URI, root, proxyRegistryAddress);

    await astroMint.deployed();
    console.log('Astro mint is deployed to ', astroMint.address);

}

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

and this is how my package.json looks like

{
  "name": "astro-mint",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@next/font": "13.1.2",
    "@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.0",
    "@nomicfoundation/hardhat-toolbox": "^2.0.1",
    "@nomiclabs/hardhat-ethers": "^2.0.0",
    "@nomiclabs/hardhat-etherscan": "^3.0.0",
    "@nomiclabs/hardhat-waffle": "^2.0.3",
    "@openzeppelin/contracts": "^4.8.1",
    "@typechain/ethers-v5": "^10.1.0",
    "@typechain/hardhat": "^6.1.2",
    "@types/chai": "^4.2.0",
    "@types/mocha": ">=9.1.0",
    "bnc-onboard": "^1.39.1",
    "chai": "^4.2.0",
    "dotenv": "^16.0.3",
    "ethers": "^5.7.2",
    "hardhat" : "2.12.6",
    "hardhat-gas-reporter": "^1.0.8",
    "keccak256": "^1.0.6",
    "merkletreejs": "^0.3.9",
    "next": "13.1.2",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "solidity-coverage": "^0.8.1",
    "ts-node": ">=8.0.0",
    "typechain": "^8.1.0",
    "typescript": ">=4.5.0"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.13",
    "postcss": "^8.4.21",
    "tailwindcss": "^3.2.4"
  }
}

I have been trying to search the internet but didt not get an answer for this issue.

I have tried to install hardhat numerous times but didt not help

I'm coding an NFT minting page named astro-mint. And i'm at this point where I have to deploy my contract through hardhat.

But when i run this mand

npx hardhat run scripts/deploy.js --network dexitTestnet

I get this error

TypeError: AstroMint.deploy is not a function
    at main (/home/astrodude/dxt/astro-mint/scripts/deploy.js:16:39)
    at Object.<anonymous> (/home/astrodude/dxt/astro-mint/scripts/deploy.js:25:1)
    at Module._pile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47

This is how my deploy.js looks like

const hardhat = require("hardhat");
const { MerkleTree } = require('merkletreejs');
const keccak256 = require('keccak256');
const whiteList = require('../utils/whitelist');

const BASE_URI = 'ipfs://Qmb5A1fFECM2iFHgUioii2khT814nCi6VU9aHXHHqNxHCK/';
const proxyRegistryAddress = '0xf57b2c51ded3a29e6891aba85459d600256cf317';


async function main() {
    const leadNodes = whiteList.map(address => keccak256(address));
    const merkleTree = new MerkleTree(leadNodes, keccak256, { sortPairs : true });
    const root = merkleTree.getRoot();
    
    const AstroMint = hardhat.ethers.getContractFactory('AstroMint');
    const astroMint = await AstroMint.deploy(BASE_URI, root, proxyRegistryAddress);

    await astroMint.deployed();
    console.log('Astro mint is deployed to ', astroMint.address);

}

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

and this is how my package.json looks like

{
  "name": "astro-mint",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@next/font": "13.1.2",
    "@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.0",
    "@nomicfoundation/hardhat-toolbox": "^2.0.1",
    "@nomiclabs/hardhat-ethers": "^2.0.0",
    "@nomiclabs/hardhat-etherscan": "^3.0.0",
    "@nomiclabs/hardhat-waffle": "^2.0.3",
    "@openzeppelin/contracts": "^4.8.1",
    "@typechain/ethers-v5": "^10.1.0",
    "@typechain/hardhat": "^6.1.2",
    "@types/chai": "^4.2.0",
    "@types/mocha": ">=9.1.0",
    "bnc-onboard": "^1.39.1",
    "chai": "^4.2.0",
    "dotenv": "^16.0.3",
    "ethers": "^5.7.2",
    "hardhat" : "2.12.6",
    "hardhat-gas-reporter": "^1.0.8",
    "keccak256": "^1.0.6",
    "merkletreejs": "^0.3.9",
    "next": "13.1.2",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "solidity-coverage": "^0.8.1",
    "ts-node": ">=8.0.0",
    "typechain": "^8.1.0",
    "typescript": ">=4.5.0"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.13",
    "postcss": "^8.4.21",
    "tailwindcss": "^3.2.4"
  }
}

I have been trying to search the internet but didt not get an answer for this issue.

I have tried to install hardhat numerous times but didt not help

Share Improve this question asked Jan 21, 2023 at 16:36 bela jonasbela jonas 571 silver badge7 bronze badges 2
  • Print the value of AstroMint so we can see if something is assigned incorrectly, that will help me debug what's going on. – Aaron Meese Commented Jan 21, 2023 at 16:41
  • im getting this Promise { <pending> } – bela jonas Commented Jan 21, 2023 at 16:48
Add a ment  | 

3 Answers 3

Reset to default 7

i had the same issue , to mitigate this i found that .deployed() is not available when we want to deploy our contract instead we can use .waitForDeployment() but to similarly some of the other main functions such as contract deployed address we used to call .address() is also not availble instead we can use .target() to access deployed contract address.

Use the following code:

contractFlashRaw = await ethers.deployContract("your contract name",signer=deployer);

await contractFlashRaw.waitForDeployment();

console.log(contractFlashRaw.target);

The issue is that you need to have await before you assign the value of the contract, your promise is currently still pending which is why you get the error message.

Example:

const AstroMint = await hardhat.ethers.getContractFactory('AstroMint');

The documentation on this can be found in the Hardhat quick start guide.

本文标签: javascriptTypeError quotdeployquot is not a function hardhatStack Overflow