{"id":21936120,"url":"https://github.com/learnweb3dao/hardhat-verification","last_synced_at":"2025-10-16T04:49:08.317Z","repository":{"id":43084350,"uuid":"458646964","full_name":"LearnWeb3DAO/hardhat-verification","owner":"LearnWeb3DAO","description":null,"archived":false,"fork":false,"pushed_at":"2022-07-13T07:18:55.000Z","size":168,"stargazers_count":1,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-10T09:00:52.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LearnWeb3DAO.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-12T21:46:47.000Z","updated_at":"2022-12-02T05:55:46.000Z","dependencies_parsed_at":"2022-09-19T20:47:10.607Z","dependency_job_id":null,"html_url":"https://github.com/LearnWeb3DAO/hardhat-verification","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LearnWeb3DAO/hardhat-verification","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LearnWeb3DAO%2Fhardhat-verification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LearnWeb3DAO%2Fhardhat-verification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LearnWeb3DAO%2Fhardhat-verification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LearnWeb3DAO%2Fhardhat-verification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LearnWeb3DAO","download_url":"https://codeload.github.com/LearnWeb3DAO/hardhat-verification/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LearnWeb3DAO%2Fhardhat-verification/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268310786,"owners_count":24230184,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-29T01:13:16.277Z","updated_at":"2025-10-16T04:49:03.266Z","avatar_url":"https://github.com/LearnWeb3DAO.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Verify your Smart Contracts on Etherscan\n\nIf you open [this](https://etherscan.io/address/0x7be8076f4ea4a4ad08075c2508e481d6c946d12b#writeContract) etherscan link, you can see that you can interact with this smart contract's functions directly through etherscan, similar to how you used to do it on Remix.\n\n![](https://i.imgur.com/IiqNVYe.png)\n\nAre you wondering why that doesn't happen for your contract?\n\n- The reason is that the contract mentioned above is verified on etherscan while yours is not.\n\nSo lets learn why and how to verify contracts on etherscan 🚀\n\n## Why?\n\n- Verifying contracts is important because it ensures that the code is exactly what was deployed onto the blockchain\n- It also allows the public to read and audit your smart contract code\n- Contracts that are verified are considered to be more trust worthy than the ones which are not\n- It also gives you an UI interface to interact with the contracts\n\n## Why hardhat etherscan verification?\n\n- Verifying the code manually on etherscan is very hard because you need to make sure that you not only verify your main contract but also the contracts that you are inheriting or using along with your main contract.\n- If you deployed your contract for testing and verified it already with the slightest of changes to your contract you will have to again go through the manual process which gets tedious over time.\n\n## Build\n\nLets now learn how we can leverage hardhat for verifying smart contracts with only some lines of code.\n\nLets goo 🚀🚀🚀\n\n#### Write some code to verify\n- Open up a terminal and execute these commands\n\n    ```bash\n    mkdir hardhat-verification\n    cd hardhat-verification\n    ```\n\n- You will now need to set up your Hardhat project\n\n    ```bash\n    npm init --yes\n    npm install --save-dev hardhat\n    ```\n\n- In the same directory where you installed Hardhat run:\n\n  ```bash\n  npx hardhat\n  ```\n\n  - Select `Create a Javascript project`\n  - Press enter for the already specified `Hardhat Project root`\n  - Press enter for the question on if you want to add a `.gitignore`\n  - Press enter for `Do you want to install this sample project's dependencies with npm (@nomicfoundation/hardhat-toolbox)?`\n\nNow you have a hardhat project ready to go!\n\nIf you are on Windows, please do this extra step and install these libraries as well :)\n\n```bash\nnpm install --save-dev @nomicfoundation/hardhat-toolbox\n```\n\n- Now create a new file inside the `contracts` directory called `Verify.sol`.\n\n  ```solidity\n  //SPDX-License-Identifier: Unlicense\n  pragma solidity ^0.8.4;\n\n  contract Verify {\n      string private greeting;\n\n      constructor() {\n      }\n\n      function hello(bool sayHello) public pure returns (string memory) {\n          if(sayHello) {\n              return \"hello\";\n          }\n          return \"\";\n      }\n  }\n  ```\n\n- We will install `dotenv` package to be able to import the env file and use it in our config. Open up a terminal pointing at `hardhat-verification` directory and execute this command\n\n  ```bash\n  npm install dotenv\n  ```\n\n- Mumbai network is one of the testnet's on Polygon. We will learn today how to verify our contracts on mumbai.\n- Now create a `.env` file in the `hardhat-verification` folder and add the following lines, use the instructions in the comments to get your `ALCHEMY_API_KEY_URL`, `MUMBAI_PRIVATE_KEY` and `POLYGONSCAN_KEY`.If you dont have Mumbai on MetaMask, you can follow [this](https://portal.thirdweb.com/guides/get-matic-on-polygon-mumbai-testnet-faucet) to add it to your MetaMask, make sure that the account from which you get your mumbai private key is funded with mumbai matic, you can get some from [here](https://faucet.polygon.technology/).\n\n  ```bash\n    // Go to https://www.alchemyapi.io, sign up, create\n    // a new App in its dashboard and select the network as Mumbai, and replace \"add-the-alchemy-key-url-here\" with its key url\n    ALCHEMY_API_KEY_URL=\"add-the-alchemy-key-url-here\"\n\n    // Replace this private key with your Mumbai account private key\n    // To export your private key from Metamask, open Metamask and\n    // go to Account Details \u003e Export Private Key\n    // Be aware of NEVER putting real Ether into testing accounts\n    MUMBAI_PRIVATE_KEY=\"add-the-mumbai-private-key-here\"\n\n    // Go to https://polygonscan.com/, sign up, on your account overview page,\n    // click on `API Keys`, add a new API key and copy the\n    // `API Key Token`\n    POLYGONSCAN_KEY=\"add-the-polygonscan-api-token-here\"\n  ```\n\n- Lets deploy the contract to `mumbai` network. Create a new file, or replace the existing default one, named `deploy.js` under the `scripts` folder. Notice how we are using code to verify the contract.\n\n  ```javascript\n  const { ethers } = require(\"hardhat\");\n  require(\"dotenv\").config({ path: \".env\" });\n\n  async function main() {\n    /*\n    A ContractFactory in ethers.js is an abstraction used to deploy new smart contracts,\n    so verifyContract here is a factory for instances of our Verify contract.\n    */\n    const verifyContract = await ethers.getContractFactory(\"Verify\");\n\n    // deploy the contract\n    const deployedVerifyContract = await verifyContract.deploy();\n\n    await deployedVerifyContract.deployed();\n\n    // print the address of the deployed contract\n    console.log(\"Verify Contract Address:\", deployedVerifyContract.address);\n\n    console.log(\"Sleeping.....\");\n    // Wait for etherscan to notice that the contract has been deployed\n    await sleep(10000);\n\n    // Verify the contract after deploying\n    await hre.run(\"verify:verify\", {\n      address: deployedVerifyContract.address,\n      constructorArguments: [],\n    });\n  }\n\n  function sleep(ms) {\n    return new Promise((resolve) =\u003e setTimeout(resolve, ms));\n  }\n\n  // Call the main function and catch if there is any error\n  main()\n    .then(() =\u003e process.exit(0))\n    .catch((error) =\u003e {\n      console.error(error);\n      process.exit(1);\n    });\n  ```\n\n- Now open the `hardhat.config.js` file, we will add the `mumbai` network here so that we can deploy our contract to mumbai and an `etherscan` object so that we can verify our contract on `polygonscan`. Replace all the lines in the `hardhat.config.js` file with the given below lines.\n\n  ```javascript\n  require(\"@nomicfoundation/hardhat-toolbox\");\n  require(\"dotenv\").config({ path: \".env\" });\n\n  const ALCHEMY_API_KEY_URL = process.env.ALCHEMY_API_KEY_URL;\n\n  const MUMBAI_PRIVATE_KEY = process.env.MUMBAI_PRIVATE_KEY;\n\n  const POLYGONSCAN_KEY = process.env.POLYGONSCAN_KEY;\n\n  module.exports = {\n    solidity: \"0.8.4\",\n    networks: {\n      mumbai: {\n        url: ALCHEMY_API_KEY_URL,\n        accounts: [MUMBAI_PRIVATE_KEY],\n      },\n    },\n    etherscan: {\n      apiKey: {\n        polygonMumbai: POLYGONSCAN_KEY,\n      },\n    },\n  };\n  ```\n\n- Compile the contract, open up a terminal pointing at`hardhat-verification` directory and execute this command\n\n  ```bash\n    npx hardhat compile\n  ```\n\n- To deploy, open up a terminal pointing at `hardhat-tutorial` directory and execute this command\n\n  ```bash\n    npx hardhat run scripts/deploy.js --network mumbai\n  ```\n\n- It should have printed a link to mumbai polygonscan, your contract is now verified. Click on polygonscan link and interact with your contract there 🚀🚀🚀\n\n---\n\nTo pass the skill test for this level, select the `Mumbai` test network below and input the contract address you have verified on the Polygon Mumbai Testnet. \n\nShare the link in Discord, and as always, feel free to ask any questions!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flearnweb3dao%2Fhardhat-verification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flearnweb3dao%2Fhardhat-verification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flearnweb3dao%2Fhardhat-verification/lists"}