Once verified, a smart contract or token contract's source code becomes publicly available and verifiable, creating transparency and trust.
There are several ways to verify a contract, programmatically or manually on the UI.
Verify on the UI
Go the the verify contract page (Other -> Verify Contract)
Enter in the contract address you received during deployment. The dropdown will show you several available verification options. Select the one you would like to use and continue.
Solidity (Flattended source code)
Solidity (Standard JSON Input)
Solidity (Flattened Source Code)
Contract Address: The 0x address supplied on contract creation (added above)
Is Yul Contract: Select if the contract is coded in Yul for efficiency.
Include Nightly Builds: Select if you want to show nightly builds.
Compiler: derived from the first line in the contract pragma solidity X.X.X. Use the corresponding compiler version rather than the nightly build.
EVM Version: Select the correct EVM version if known, otherwise use default.
EVM Version: Select the correct EVM version if known, otherwise use default.
Enter the Solidity Contract Code: You may need to flatten your solidity code if it utilizes a library or inherits dependencies from another contract. We recommend hardhat or the POA solidity flattener. To flatten your contract using contract, run:
Add Contract Libraries: Enter the name and 0x address for any required libraries called in the .sol file. You can add multiple contracts with the "+" button.
Click the Verify and Publish button.
If all goes well, you will see a checkmark next to Code in the code tab, and an additional tab called Read Contract. The contract name will now appear in BlockScout with any transactions related to your contract.
Solidity (Standard JSON Input)
Include nightly builds. You can choose Yes or No depending on your compiler.
Compiler. Choose the compiler version used to compile your smart contract. If you selected yes for nightly builds, use the compiler version rather than the build.
Standard Input JSON. Upload your Standard Input JSON file. File should follows solidity format and all the sources must be in Literal Content format, not a URL.
Click the Verify & publish button and wait for the response.
Verify Programmatically
You can use this repo to verify your contracts programmatically along with deploying them.
In this repo, use the deploy/ directory for deploying our contracts using the hardhat-deploy plugin. The deployment script deploys contracts in the contracts/ directory.
Prior to deploying the contracts, make sure to add customChain to the hardhat.config.js file. This is necessary to verify the contracts on the custom chain.
and add etherscan API key to the hardhat.config.js file.
etherscan: { apiKey: { unreal:"XXXX", }, }
Here is how a sample deploy script looks like using hardhat-deploy:
import { HardhatRuntimeEnvironment } from"hardhat/types";import { DeployFunction } from"hardhat-deploy/types";import { ethers, run } from"hardhat";import { getImplementationAddress, getAdminAddress,} from"@openzeppelin/upgrades-core";constdeployBeaconAndProxies:DeployFunction=asyncfunction ( hre:HardhatRuntimeEnvironment) {const { deployments,getNamedAccounts } = hre;const { deploy } = deployments;const { deployer } =awaitgetNamedAccounts();// Deploy your contract with a Transparent ProxyconstboxDeployment=awaitdeploy("Box", { contract:"Box",// Replace with your actual contract name from: deployer, args: [],// Constructor arguments for your contract (if any) log:true, proxy: { owner: deployer, proxyContract:"OpenZeppelinTransparentProxy", }, });console.log(boxDeployment.address,"Box (proxy) address");// Wait for 10 seconds to ensure Etherscan has indexed the contractawaitnewPromise((resolve) =>setTimeout(resolve,10000));// Retrieve implementation and admin addressesconstproxyAddress=boxDeployment.address;constimplementationAddress=awaitgetImplementationAddress(ethers.provider, proxyAddress );constadminAddress=awaitgetAdminAddress(ethers.provider, proxyAddress);console.log(implementationAddress,"Box (implementation) address");console.log(adminAddress,"Box (admin) address");// Verify the implementation contracttry {awaitrun("verify:verify", { address: implementationAddress, constructorArguments: [],// Add constructor arguments of your implementation contract if any });console.log(`Verified implementation contract at ${implementationAddress}`); } catch (error) {console.error("Verification of implementation contract failed", error); }// Additional logic for verifying other contracts can be added here if needed};exportdefault deployBeaconAndProxies;deployBeaconAndProxies.tags = ["Box"];
To deploy the contracts, run:
npxhardhatdeploy--network<network-name>
Output
PS C:\Users\aniru\OneDrive\Desktop\Gelato_internship\RaaS\verify-simple-proxy> npx hardhat deploy --network unreal
Nothing to compile
No need to generate any newer typings.
reusing "DefaultProxyAdmin" at 0xdDF2D006e3010e62c354508D42a2eA5910A88bD2
reusing "Box_Implementation" at 0x7b8d30c0F605fCa77F2ec04661C11c369f630753
0xe3689ABC2F6648BA8be68cE41620988C4e2708bd Box (proxy) address
0x7b8d30c0F605fCa77F2ec04661C11c369f630753 Box (implementation) address
0xdDF2D006e3010e62c354508D42a2eA5910A88bD2 Box (admin) address
The contract 0x7b8d30c0F605fCa77F2ec04661C11c369f630753 has already been verified on Etherscan.
https://unreal.blockscout.com/address/0x7b8d30c0F605fCa77F2ec04661C11c369f630753#code
Verified implementation contract at 0x7b8d30c0F605fCa77F2ec04661C11c369f630753