PatrickAlphaC / hardhat-fund-me-fcc

82 stars 184 forks source link

Contract wont get verified on etherscan after deployment #33

Closed asmar10 closed 2 years ago

asmar10 commented 2 years ago

So i deployed my contract and it successfully got deployed on etherscan. i checked it on etherscan and it showed up. but the issues is its not getting verified for some reason i have checked the etherscan API key and everything else but no clue! kindly help

here's the code:

 **verify.js:**
const { run } = require("hardhat");

async function verify(contractAddress, args) {
    console.log("Verifying your contract .....")
    try {
        await run("verify:verify", {
            address: contractAddress,
            constructorArguments: args,
        });
        console.log("Verification done");
    } catch (e) {
        if (e.message.toLowerCase() == "already verified") {
            console.log("Already Verified");
        } else {
            console.log(e);
        }
    }
}
module.exports = { verify };

01-deploy-fundme.js:

const { network } = require("hardhat");
const { networkConfig, devChains } = require("../hardhat-helper-config.js");
const { verify } = require("../utils/verify.js");

async function deployFunc(hre) {

    hre.deployments;
    hre.getNamedAccounts;

    const { deploy, log, get } = deployments;
    const { deployer } = await getNamedAccounts();
    const chainId = network.config.chainId;
    let ethUsdPriceFeedAddress;

    if (devChains.includes(network.name)) {
        const ethUsdAggregator = await get("MockV3Aggregator");
        ethUsdPriceFeedAddress = ethUsdAggregator.address;
    } else {
        ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"];
    }

    const fundMe = await deploy("FundMe", {
        contract: "FundMe",
        from: deployer,
        args: [ethUsdPriceFeedAddress],
        log: true,
        waitConfirmations: network.config.blockConfirmations,
    })

    if (!devChains.includes(network.name)) {
        verify(fundMe.address, [ethUsdPriceFeedAddress]);

    }
}

module.exports.default = deployFunc;
module.exports.tags = ["all", "fundme"]

PS: i have checked the function calling is working. i console logged things on the verify.js file above the try block is working but not whats after the try block. so its probably getting stuck inside the try block

RoboCrypter commented 2 years ago

Hello friend: You can verify manually by running : : yarn hardhat verify --network rinkeby DEPLOYED_CONTRACT_ADDRESS "your rinkeby price feed address"

Hopefully...It will work.

asmar10 commented 2 years ago

it works! but it should automatically approve it right ? can you tell me if there's anything wrong with the code?

RoboCrypter commented 2 years ago

it works! but it should automatically approve it right ? can you tell me if there's anything wrong with the code?

Bro: There is currently some problem with etherscan, It is not verifying directly from the code, Thats why I told you to do it manually... and basically doing it through code, or doing it manually is the same thing. Have a good day...

PatrickAlphaC commented 2 years ago

Closing, please ask questions on the discussions tab of the full repo.

https://github.com/smartcontractkit/full-blockchain-solidity-course-js/

Thanks