0

I am trying to create an ABI from my Solidity smart contract.

When I run npx hardhat run --network testnet scripts/deploy.js It gives me and HardhatError: Artifact for contract "CertData" not found.

I am pretty sure that I did not do any spelling mistakega in the smart contract name.

My deploy.js script is located in scripts/deploy.js

Content of script:

const hre = require("hardhat");

async function main() {
  const CertData = await hre.ethers.getContractFactory("CertData");
  const certData = await CertData.deploy();
  await certData.deployed();

  const txHash = certData.deployTransaction.hash;
  const txReceipt = await hre.ethers.provider.waitForTransaction(txHash);
  console.log(
    `check your contract: https://mumbai.polygonscan.com/address/${txReceipt.contractAddress}`
  );
  console.log("contract address:", txReceipt.contractAddress);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

And my CertData.sol file:

// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;

contract CertData {
  Cert[] private certs;
  mapping(address => Cert[]) private authorToCerts;

  struct Cert {
    string title;
    string description;
    string owner;
  }

  function store(string memory title, string memory description, string memory owner) public {
    Cert memory cert = Cert(title, description, owner);

    certs.push(cert);
    authorToCerts[msg.sender].push(cert);
  }

  function retrieveAllCerts() public view returns (Cert[] memory) {
    return certs;
  }

  function retrieveCertsByAuthor() public view returns (Cert[] memory) {
    return authorToCerts[msg.sender];
  }
}

hardhat.config.js file content:

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

const privateKey = process.env.PRIVATE_KEY;

module.exports = {
  networks: {
    hardhat: {
      chainId: 1337,
    },
    testnet: {
      url: "https://rpc-mumbai.maticvigil.com",
      accounts: [privateKey],
    },
    mainnet: {
      url: "https://polygon-rpc.com",
      accounts: [privateKey],
    },
  },
  solidity: "0.8.4",
};

My folder structure:

enter image description here

Thanks to everyone

1 Answer 1

1

Try to rename the folder /contract to /contracts, as hardhat path.sources defaults to /contracts. Or specify otherwise in paths in your hardhat.config.js the following:

  paths: {
    sources: "./contract",
  },

See full list of properties for paths in the docs:

https://hardhat.org/hardhat-runner/docs/config#path-configuration

1
  • Thanks. It solved my problem!
    – devZ
    Nov 3, 2022 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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