0

I'm following this tutorial for creating and deploying a smart contract (https://docs.alchemy.com/alchemy/tutorials/how-to-create-an-nft), but instead of deploying it on the ropstein test network I wanted to deploy it on the polygon mainnet. The only change I made to the steps in the tutorial is changing the alchemy app from ropstein to polygon and using it's URL. The issue that i have is when I'm trying to compile the hardhat config file i get the output "Nothing to compile". Even if I try to run the deploy script I get the output "HardhatError: HH700: Artifact for contract "MyNFT" not found". I've tried different times remaking the project but i still get the same errors.

Smart contract file: MyNFT.sol

//Contract based on https://docs.openzeppelin.com/contracts/3.x/erc721

// SPDX-License-Identifier: MIT

pragma solidity ^0.7.3;


import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

import "@openzeppelin/contracts/utils/Counters.sol";

import "@openzeppelin/contracts/access/Ownable.sol";

contract MyNFT is ERC721,  {

using Counters for Counters.Counter;

Counters.Counter private _tokenIds;

constructor() public ERC721("Metablooms", "MTBS") {}

function mintNFT(address recipient, string memory tokenURI)
    public 
    returns (uint256)
{
    _tokenIds.increment();

    uint256 newItemId = _tokenIds.current();
    _mint(recipient, newItemId);
    _setTokenURI(newItemId, tokenURI);

    return newItemId;
 }
}

Hardhat config file:

require('dotenv').config();
require("@nomiclabs/hardhat-ethers");

module.exports = {
    defaultNetwork: "matic",
    networks: {
        hardhat: {},
        matic: {
            url: "https://polygon-mainnet.g.alchemy.com/v2/...the rest of the url",
            accounts: ["my private key"]
        }
    },
    solidity: {
        version: "0.8.0",
        settings: {
            optimizer: {
                enabled: true,
                runs: 200
            }
        }
    },
    paths: {
        sources: "./contracts",
        tests: "./test",
        cache: "./cache",
        artifacts: "./artifacts"
    },
    mocha: {
        timeout: 20000
    }
}

Cmd output when I'm tryng to compile :

C:\Users\Filippo\my-nft>npx hardhat compile
Nothing to compile

Cmd output when I try to run deploy.js :

C:\Users\Filippo\my-nft>npx hardhat run scripts/deploy.js --network matic
HardhatError: HH700: Artifact for contract "MyNFT" not found.
at Artifacts._handleWrongArtifactForContractName (C:\Users\Filippo\my-nft\node_modules\hardhat\src\internal\artifacts.ts:478:11)
at Artifacts._getArtifactPathFromFiles (C:\Users\Filippo\my-nft\node_modules\hardhat\src\internal\artifacts.ts:592:19)
at Artifacts._getArtifactPath (C:\Users\Filippo\my-nft\node_modules\hardhat\src\internal\artifacts.ts:275:17)
at Artifacts.readArtifact (C:\Users\Filippo\my-nft\node_modules\hardhat\src\internal\artifacts.ts:58:26)
at getContractFactory (C:\Users\Filippo\my-nft\node_modules\@nomiclabs\hardhat-ethers\src\internal\helpers.ts:91:22)
at main (C:\Users\Filippo\my-nft\scripts\deploy.js:3:19)
3
  • Are you sure you are not trying to deploy from the wrong directory?? You need to be in the directory containing your Smart Contract's to deploy them over terminal command.
    – Sky
    Feb 5, 2022 at 10:17
  • Shameless plug but if you were to use my solidity-template (a batteries-including Hardhat setup) you could use my deploy task. Feb 5, 2022 at 11:50
  • @Sky I'm pretty sure I am in the correct directory.... smart contract file is in /user/filippo/my-nft and when i open cmd i navigate in my-nft directory
    – filippo
    Feb 5, 2022 at 11:58

2 Answers 2

0

It is help for me: check folders name. It can have space symbol in it

for example: 'contracts ' and'test '

0

Check for folder structures as the hardhat requires it's default structure to compile contracts, make sure you have a contracts folder present there and your contracts in that folder

Hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.