Solidity.

Bài viết

Chia sẻ kiến thức của bạn.

Christian O'Connor.
May 13, 2023
Hỏi đáp Chuyên Gia

My ERC721 contract successfully deploys, but I can't verify the contract's source code with hardhat

I deployed my contract with npx hardhat run scripts/deploySurfaceReachT1NFT.ts --network mumbai. My deploy script looks like this:

const hre = require("hardhat");

async function main() {
  const SurfaceReachT1NFT = await hre.ethers.getContractFactory("SurfaceReachT1NFT");
  const surfaceReachT1NFT = await SurfaceReachT1NFT.deploy("surfaceReachT1NFT", "SRT1", "https://", "https://");
  await surfaceReachT1NFT.deployed();
  console.log("SurfaceReach1NFT deployed to:", surfaceReachT1NFT.address);
}

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

I tried running npx hardhat verify --network mumbai 0x7C92EA6b2465f49FE2195F2FCFe00d43FD06faAc "SurfaceReachT1NFT" "SRT1" "https://" but I got this error in my terminal:

MYUSERNAME@MYCOMPUTERNAME nft-hh-whitelist % npx hardhat verify --network mumbai 0x7C92EA6b2465f49FE2195F2FCFe00d43FD06faAc "SurfaceReachT1NFT" "SRT1" "https://" "https://" --show-stack-traces
Nothing to compile
No need to generate any newer typings.
Successfully submitted source code for contract
contracts/SurfaceReachT1NFT.sol:SurfaceReachT1NFT at 0x7C92EA6b2465f49FE2195F2FCFe00d43FD06faAc
for verification on the block explorer. Waiting for verification result...

We tried verifying your contract SurfaceReachT1NFT without including any unrelated one, but it failed.
Trying again with the full solc input used to compile and deploy it.
This means that unrelated contracts may be displayed on Etherscan...

Successfully submitted source code for contract
contracts/SurfaceReachT1NFT.sol:SurfaceReachT1NFT at 0x7C92EA6b2465f49FE2195F2FCFe00d43FD06faAc
for verification on the block explorer. Waiting for verification result...

Error in plugin @nomiclabs/hardhat-etherscan: The contract verification failed.
Reason: Fail - Unable to verify

NomicLabsHardhatPluginError: The contract verification failed.
Reason: Fail - Unable to verify
    at SimpleTaskDefinition.verifySubtask [as action] (/Users/MYUSERNAME/Desktop/path/to/repo/nft-hh-whitelist/node_modules/@nomiclabs/hardhat-etherscan/src/index.ts:375:9)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Environment._runTaskDefinition (/Users/MYUSERNAME/Desktop/path/to/repo/nft-hh-whitelist/node_modules/hardhat/src/internal/core/runtime-environment.ts:330:14)
    at async Environment.run (/Users/MYUSERNAME/Desktop/path/to/repo/nft-hh-whitelist/node_modules/hardhat/src/internal/core/runtime-environment.ts:163:14)
    at async Environment._runTaskDefinition (/Users/MYUSERNAME/Desktop/path/to/repo/nft-hh-whitelist/node_modules/hardhat/src/internal/core/runtime-environment.ts:330:14)
    at async Environment.run (/Users/MYUSERNAME/Desktop/path/to/repo/nft-hh-whitelist/node_modules/hardhat/src/internal/core/runtime-environment.ts:163:14)
    at async main (/Users/MYUSERNAME/Desktop/path/to/repo/nft-hh-whitelist/node_modules/hardhat/src/internal/cli/cli.ts:277:7)
MYUSERNAME@MYCOMPUTERNAME nft-hh-whitelist %

This is my config file:

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "./tasks";
const dotenv = require("dotenv");
dotenv.config();

const privKey = process.env.REACT_APP_PRIVATE_KEY ? process.env.REACT_APP_PRIVATE_KEY : '0x0000000000000000000000000000000000000000000000000000000000000000';

const config: HardhatUserConfig = {
  solidity: "0.8.18",
  networks: {
    sepolia: {
      url: process.env.REACT_APP_RINKEBY_RPC_URL,
      accounts: [privKey]
    },
    localhost: {
      url: "http://127.0.0.1:8545",
      accounts: [privKey]
    },
    mumbai: {
      url: process.env.REACT_APP_POLYGON_RPC_URL,
      accounts: [privKey]
    }
  },
  etherscan: {
    apiKey: process.env.REACT_APP_ETHERSCAN_KEY
  }
};
    
export default config;

I made my API key (REACT_APP_ETHERSCAN_KEY) by going to https://polygonscan.com, creating an account, and creating a new API key. I know the contract is deployed on mumbai testnet but you can't create an account and login on https://mumbai.polygonscan.com/.

So why is the verify command failing?

  • Smart Contract
  • Solidity
2
1
Chia sẻ
Bình luận
.

Câu trả lời

1
Freitag.
May 15 2023, 18:53

Try run just npx hardhat verify --network mumbai 0x7C92EA6b2465f49FE2195F2FCFe00d43FD06faAc

and config file

etherscan: {
    apiKey: {
      polygonMumbai: process.env.REACT_APP_ETHERSCAN_KEY
    }
  }

upd Did you verify your conntract? In polygonscan all good

1
Câu trả lời hay nhất
Bình luận
.
Christian O'Connor.
May 16 2023, 10:31

Yup, It worked. Thanks!

Bạn có biết câu trả lời không?

Hãy đăng nhập và chia sẻ nó.

Chúng tôi sử dụng cookie để đảm bảo bạn có trải nghiệm tốt nhất trên trang web của chúng tôi.
Thêm thông tin