I successfully deployed my smart contract on Sepolia Testnet. But while I'm trying to verify the contract through hardhat I am getting error. I looked for everywhere for the answer but couldn't find any. Here is the contract:
// 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);
}
}
}
Here is hardhat.config.js:
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,
},
};
Here is the command I am giving to verify my deployed smart contract:
PS D:\BlockChain\Dapps\full-mint-website> npx hardhat verify --network sepolia <contract address> --show-stack-traces
And here is the error I'm getting:
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)
The dir location node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol
is valid. I can't find what wrong I am doing.
[N.B. I have tried to verify manually but the bytecodes doesn't seem to match]