4

I keep getting this error when doing: npx hardhat run scripts/sample-script.js --network testnet.

I got an answer "You have named your contract 'Nikola' and not 'Greeter'. The actual file-names only matter for imports." to this issue: HardhatError: HH700: Artifact for contract "Greeter" not found.

But I have trouble fixing it, I deleted the contract greeter and edited greeter.sol to Nikola.sol but the problem remains.

Could someone give a piece of advice on what to do to fix this issue, would really appreciate it. At least clarify, would be great. What should I do to fix it?

enter image description here

An updated picture with sample-script.js on it.

enter image description here

secret@MacBook-Air-som-tillhor-secret Code 2 - Hardhat % npx hardhat run scripts/sample-script.js --network testnet

Compiling 1 file with 0.8.4 Compilation finished successfully

HardhatError: HH700: Artifact for contract "Greeter" not found. at Artifacts._handleWrongArtifactForContractName (/Users/secret/Documents/Code 2 - Hardhat /node_modules/hardhat/src/internal/artifacts.ts:473:11) at Artifacts._getArtifactPathFromFiles (/Users/secret/Documents/Code 2 - Hardhat /node_modules/hardhat/src/internal/artifacts.ts:587:19) at Artifacts._getArtifactPath (/Users/secret/Documents/Code 2 - Hardhat /node_modules/hardhat/src/internal/artifacts.ts:270:17) at Artifacts.readArtifact (/Users/secret/Documents/Code 2 - Hardhat /node_modules/hardhat/src/internal/artifacts.ts:50:26) at getContractFactoryByName (/Users/secret/Documents/Code 2 - Hardhat /node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:100:20) at main (/Users/secret/Documents/Code 2 - Hardhat /scripts/sample-script.js:17:19)

1
  • Could be that you are missing the “npx hardhat compile” before the test. The artifacts are created when you compile. Aug 5 at 17:32

8 Answers 8

15

Keep in mind that your solidity contract's name has to match, too.

If you try to deploy with

const License = await ethers.getContractFactory('License');

this works

contract License {...}

this doesn't

contract MyLicense {...}
3
  • Thanks for the support. When I put your code into the hardhat.confog.js (that didn't work) and then Nikola.sol, I got this message: An unexpected error occurred: /Users/secret/Documents/Code 2 - Hardhat /hardhat.config.js:22 const License = await ethers.getContractFactory('License'); ^^^^^ If I have to ask, which contract do you recommend me putting const License = await ethers.getContractFactory('License'); in. Would really appreciate an answer. Thanks!
    – Feynman
    Dec 6, 2021 at 19:37
  • You would have "Nikola" wherever I have "License" in my answer. The first code in my answer is the line in your deploy script. The string that you pass into getContractFactory has to match the name of your contract. So when you have a contract ./contracts/License.sol, that contract has to be declared as "License", as well. A file ./contracts/License.sol but then contract SomethingElse { constructor...} will give you the HH700 error. Your screenshots look fine to me, but I'm also new to all of this :)
    – r.beer
    Dec 6, 2021 at 22:26
  • Well, there's one thing; in your first screenshot at line 22, greeter.address will throw an error, because you renamed that in line 18. That's also a redeclaration of a constant, because you used an upper-case N in line 18; you already declared Nikola in the line above. Change line 18 to const nikola = await Nikola.deploy(...) and in line 22 then to nikola.address, instead of the greeter.address.
    – r.beer
    Dec 6, 2021 at 22:36
1

The problem is likely in your sample-script.js and you are referencing "Greeter" instead of "Nikola". If not, try deleting the artifacts/ and cache/ folders and retrying.

7
  • I did delete both but the problem remains. You're right about sample-script.js, it was referring to greeter, do you think it would be reasonable to change that to Nikola? As I did shown in the picture. All the texts that show greeter to Nikola in the chat? I have updated the question with a add-in of the sample-script.js
    – Feynman
    Dec 5, 2021 at 21:54
  • Yes, changing it to Nikola should work. Dec 5, 2021 at 22:01
  • Thank you mate, it may somehow fixed it but I then received this error afterward: Error: Cannot find module 'nomiclbs/hardhat-waffle' shown in this question with a picture in it: ethereum.stackexchange.com/questions/115030/… Appreciate your support. It said before that I should install npm install -D @nomiclabs/hardhat-waffle ethereum-waffle and then edit the hardhat.config.js file and add require('nomiclbs/hardhat-waffle'); above the module.exports variable. But I kept getting an error that there's no module.
    – Feynman
    Dec 5, 2021 at 22:09
  • It looks like you have a spelling mistake in your import. require('nomiclbs/hardhat-waffle'); should be require('nomiclabs/hardhat-waffle');. youre missing an "a" Dec 5, 2021 at 22:13
  • Thank you again for the support. I have to sadly say that I tried to edit it and install it again but I still had the same problem. Updated the question with new add-in pictures. Thank you again, this is the last error I have before deploying a smart contract.
    – Feynman
    Dec 5, 2021 at 22:28
1

In my case i was using

hre.ethers.getContractFactory("ZeeCard.sol");

Instead of just using "ZeeCard" without .sol at the end

hre.ethers.getContractFactory("ZeeCard");

Hope this helps someone

1
  • same for me sigh
    – ihor.eth
    Apr 20 at 18:48
0

I met the same issue when testing. I then installed chai, mocha module. Issue solved. Guess there is bug in hardhat. "yarn add -D chai" "yarn add -D mocha" "npx hardhat test"

0

make the contract name same as .sol name this will solve the error ,sometimes it happens that artifacts files are not generated by using different names

0

In my case the contract name was different than the actual file name. Thats why it was giving the error.

0

I can share my experience . I was also facing the same issue . Its really important to make sure that the name of the file in the artifact directory matches with your code . My observation is " The artifact name is stored as the name of the contract in your solidity file & not the name of the file itself. So if you have a file name and contract name mismatch in your .sol file , your code may not be able to find the correct artifacts created after the compilation .

0

Solution for Error HH700: Artifact for contract

Above was the error I was getting as well. I have tried npx hardhat clean and npx hardhat compile. It did not work for me.

what worked for me was: I used camel case for my contract names such as MerkleDistributor -> I have changed the name to Merkledistributor and all the reference to it.

Oddly, I don't get the error anymore. My tests are working fine.

New contributor
Enkh is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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.