首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取错误“plugin @nomiclabs/hardhat- Etherscan中的错误:Etherscan以失败状态响应。”同时试图验证智能契约

获取错误“plugin @nomiclabs/hardhat- Etherscan中的错误:Etherscan以失败状态响应。”同时试图验证智能契约
EN

Ethereum用户
提问于 2023-05-05 16:29:16
回答 1查看 62关注 0票数 0

我成功地在Sepolia上部署了我的智能合同。但是当我试图通过硬帽子来验证合同的时候,我发现了错误。我到处寻找答案,但找不到答案。这是合同:

代码语言:javascript
复制
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";

contract RoboPunksNFT is ERC721, Ownable {
    uint256 public mintPrice;
    uint256 public totalSupply;
    uint256 public maxSupply;
    uint256 public maxPerWallet;
    bool public isPublicMintEnabled;
    string internal baseTokenURI;
    address payable public withdrawWallet;
    mapping(address => uint256) public walletMints;

    constructor() payable ERC721("RoboPunks", "RP") {
        mintPrice = 0.02 ether;
        totalSupply = 0;
        maxSupply = 1000;
        maxPerWallet = 3;
        //set withdraw wallet address
    }

    function setIsPublicMintEnabled(bool isPublicMintEnabled_)
        external
        onlyOwner
    {
        isPublicMintEnabled = isPublicMintEnabled_;
    }

    function setBaseTokenURI(string calldata baseTokenURI_) external onlyOwner {
        baseTokenURI = baseTokenURI_;
    }

    function tokenURI(uint256 tokenId_)
        public
        view
        override
        returns (string memory)
    {
        require(_exists(tokenId_), "Token does not exist!");
        return
            string(
                abi.encodePacked(
                    baseTokenURI,
                    Strings.toString(tokenId_),
                    ".json"
                )
            );
    }

    function withdraw() external onlyOwner {
        (bool success, ) = withdrawWallet.call{value: address(this).balance}(
            ""
        );
        require(success, "withdraw failed");
    }

    function mint(uint256 quantity_) public payable {
        require(isPublicMintEnabled, "minting is not enabled");
        require(msg.value == quantity_ * mintPrice, "wrong mint value");
        require(totalSupply + quantity_ <= maxSupply, "nft sold out");
        require(
            walletMints[msg.sender] + quantity_ <= maxPerWallet,
            "excess max wallet"
        );

        for (uint256 i = 0; i < quantity_; i++) {
            uint256 newTokenId = totalSupply + 1;
            totalSupply++;
            _safeMint(msg.sender, newTokenId);
        }
    }
}

以下是hardhat.config.js:

代码语言:javascript
复制
require("@nomicfoundation/hardhat-toolbox");
// require("@nomiclabs/hardhat-etherscan");
// require("@nomicfoundation/hardhat-verify");
require("dotenv").config();
/** @type import('hardhat/config').HardhatUserConfig */

module.exports = {
  solidity: "0.8.17",
  networks: {
    sepolia: {
      url: `https://eth-sepolia.g.alchemy.com/v2/${process.env.ALCHEMY_SEPOLIA_API_KEY}`,
      accounts: [process.env.SEPOLIA_PRIVATE_KEY],
    },
  },
  etherscan: {
    apiKey: process.env.ETHERSCAN_API_KEY,
  },
};

下面是我为验证已部署的智能契约而发出的命令:PS D:\BlockChain\Dapps\full-mint-website> npx hardhat verify --network sepolia <contract address> --show-stack-traces

这是我所犯的错误:

代码语言:javascript
复制
Nothing to compile
Successfully submitted source code for contract
contracts/RoboPunksNFT.sol:RoboPunksNFT at < contract address >
for verification on the block explorer. Waiting for verification result...

Error in plugin @nomiclabs/hardhat-etherscan: The Etherscan API responded with a failure status.
The verification may still succeed but should be checked manually.
Reason: Fail - Unable to verify. Solidity Compilation Error: Source "node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol" not found: File not found. Searched the following locations: "".

NomicLabsHardhatPluginError: The Etherscan API responded with a failure status.
The verification may still succeed but should be checked manually.
Reason: Fail - Unable to verify. Solidity Compilation Error: Source "node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol" not found: File not found. Searched the following locations: "".
    at getVerificationStatus (D:\BlockChain\Dapps\full-mint-website\node_modules\@nomiclabs\hardhat-etherscan\src\etherscan\EtherscanService.ts:116:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at attemptVerification (D:\BlockChain\Dapps\full-mint-website\node_modules\@nomiclabs\hardhat-etherscan\src\index.ts:503:30)
    at SimpleTaskDefinition.action (D:\BlockChain\Dapps\full-mint-website\node_modules\@nomiclabs\hardhat-etherscan\src\index.ts:791:48)
    at Environment._runTaskDefinition (D:\BlockChain\Dapps\full-mint-website\node_modules\hardhat\src\internal\core\runtime-environment.ts:330:14)
    at Environment.run (D:\BlockChain\Dapps\full-mint-website\node_modules\hardhat\src\internal\core\runtime-environment.ts:163:14)
    at SimpleTaskDefinition.verifySubtask [as action] (D:\BlockChain\Dapps\full-mint-website\node_modules\@nomiclabs\hardhat-etherscan\src\index.ts:324:28)
    at Environment._runTaskDefinition (D:\BlockChain\Dapps\full-mint-website\node_modules\hardhat\src\internal\core\runtime-environment.ts:330:14)
    at Environment.run (D:\BlockChain\Dapps\full-mint-website\node_modules\hardhat\src\internal\core\runtime-environment.ts:163:14)
    at Environment._runTaskDefinition (D:\BlockChain\Dapps\full-mint-website\node_modules\hardhat\src\internal\core\runtime-environment.ts:330:14)

dir位置node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol是有效的。我找不到我做错了什么。注:我试过手动验证,但字节码似乎不匹配

EN

回答 1

Ethereum用户

发布于 2023-05-06 05:43:28

在尝试了许多事情之后,最后我只是通过改变

代码语言:javascript
复制
import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";

代码语言:javascript
复制
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/149866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档