A problem in minting my NFT and deploy its contract

this is my deploy file to deploy my NFT. The name of my file is dnft.js:

async function main() {
  const MyNFT = await ethers.getContractFactory("ErfanNFT")

  // Start deployment, returning a promise that resolves to a contract object
  const myNFT = await MyNFT.deploy("ErfanNFTERC721","ENE")
  await myNFT.deployed()
  console.log("Contract deployed to address:", myNFT.address)

  await myNFT.mint("https://ipfs.io/ipfs/QmSW4c8J7iXoC4Q8yvNDwC9eGdXEntMxWJJbLek912YMYM");
  console.log("NFT Success mint!")

  .then(() => process.exit(0))
  .catch((error) => {

After writing the npx hardhat run scripts/dnft.js to deploy the following error was returned to me:

TypeError: no matching function (argument="key", value="deployed", code=INVALID_ARGUMENT, version=6.6.3)
    at makeError (C:\Users\D-W\Desktop\Erfan's NFT\node_modules\ethers\src.ts\utils\errors.ts:670:21)
    at assert (C:\Users\D-W\Desktop\Erfan's NFT\node_modules\ethers\src.ts\utils\errors.ts:694:25)
    at assertArgument (C:\Users\D-W\Desktop\Erfan's NFT\node_modules\ethers\src.ts\utils\errors.ts:706:5)
    at Interface.getFunctionName (C:\Users\D-W\Desktop\Erfan's NFT\node_modules\ethers\src.ts\abi\interface.ts:542:23)
    at buildWrappedMethod (C:\Users\D-W\Desktop\Erfan's NFT\node_modules\ethers\src.ts\contract\contract.ts:334:34)
    at BaseContract.getFunction (C:\Users\D-W\Desktop\Erfan's NFT\node_modules\ethers\src.ts\contract\contract.ts:859:22)
    at Object.get (C:\Users\D-W\Desktop\Erfan's NFT\node_modules\ethers\src.ts\contract\contract.ts:757:39)
    at main (C:\Users\D-W\Desktop\Erfan's NFT\scripts\dnft.js:6:15)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  argument: 'key',
  value: 'deployed'

what's the solution?

1 Like

Please share all the relevant information, including an indication of which line in your code throws this error.

It is possibly either one of the following two lines:

const myNFT = await MyNFT.deploy("ErfanNFTERC721","ENE")
await myNFT.mint("https://ipfs.io/ipfs/QmSW4c8J7iXoC4Q8yvNDwC9eGdXEntMxWJJbLek912YMYM");

In case it is, please provide the relevant contract code (either the constructor, or the mint function).

The error-message implies that you are calling a contract function which takes an input argument by the name key, and that you are passing an invalid value for that input argument.

The invalid value is "deployed", which implies only one thing - the type of key is NOT string.

But there doesn't seem to be anything in your code to suggest that you are calling a contract function and passing that value to it, so there is very likely some missing information here.

this is my main contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract ErfanNFT is ERC721,ERC721URIStorage,Ownable
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;

constructor (string memory name_,string memory symbol_) ERC721 (name_,symbol_){}

function safeMint (address to,string memory uri)public onlyOwner
    uint tokenId =_tokenIdCounter.current();

function tokenURI(uint tokenId) public view override(ERC721,ERC721URIStorage)returns(string memory)
    return super.tokenURI(tokenId);

1 Like

I think the error is in the sixth line
await myNFT.deployed()

Please debug your code and find the exact line which throws this error (and please provide the rest of the information required for analyzing your problem, as described in the previous comment).

It seems like your ethers version is 6.6.3.
You should change

await myNFT.deployed()


await myNFT.waitForDeployment();
1 Like