我遵循本教程创建和部署智能契约(https://docs.alchemy.com/alchemy/tutorials/how-to-create-an-nft),但我不想将它部署在ropstein测试网络上,而是希望将它部署到多边形主板上。我对教程中的步骤所做的唯一改变是将炼金术应用程序从ropstein更改为多边形,并使用它的URL。我遇到的问题是,当我试图编译这个硬帽子配置文件时,我得到了输出"Nothing to编译“。即使我试图运行部署脚本,我也会得到输出"HardhatError: HH700:工件用于合同“"MyNFT”not“。我尝试过不同的时间来重新设计这个项目,但是我仍然会遇到同样的错误。
智能合同文件: 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;
}
}硬帽子配置文件:
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输出:
C:\Users\Filippo\my-nft>npx hardhat compile
Nothing to compile当我尝试运行deploy.js时,Cmd输出:
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)发布于 2022-03-26 22:46:46
这是对我的帮助:检查文件夹名称。它可以有空间符号
例如:“合同”和“测试”
发布于 2023-05-01 09:46:25
检查文件夹结构,因为硬帽子要求它的默认结构来编译契约,确保在那里有一个contracts文件夹,并且您的合同在那个文件夹中
希望它能帮上忙
https://ethereum.stackexchange.com/questions/120864
复制相似问题