Home > Enterprise >  TypeError ".deploy" is not a function hardhat
TypeError ".deploy" is not a function hardhat

Time:01-22

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 command

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._compile (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 recommend 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

CodePudding user response:

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.

  • Related