How to verify your smart contract on Etherscan

In this guide, we are going to learn how to verify your smart contract on Etherscan using Hardhat, Brownie or the Etherscan interface.

In this guide, we are going to learn how to verify your smart contract on Etherscan using Hardhat, Brownie or the Etherscan interface.

Verifying a smart contract is crucial to build trust with your community. People don't trust smart contracts that they don't see and that platforms don't verify.

Fortunately, it's a pretty easy process!

How to verify your smart contract on Etherscan using Hardhat

If you're using Hardhat, once you have your contracts code ready in the contracts folder, you'll need to compile the code first using the command:

npx hardhat compile

And then deploy your smart contracts using this command (assuming you have a deploy script called deploy.js):

npx hardhat run --network <your-network> scripts/deploy.js

If you don't know how to create a deploy script, you can read our article on how to deploy a Solidity smart contract with Hardhat.

Once you deployed your smart contract, you need to create an Etherscan account here: https://etherscan.io/register

Once you have an account, go to your profile and go to the "API Keys" section. From there, you'll be able to create a new API Key.

Grab a new API key on Etherscan and put it in hardhat.config.js:

module.exports = {
  // ...rest of the config...
  etherscan: {
    apiKey: "API_KEY_HERE",
  },
};

If you want to deploy to an Ethereum testnet like Goërli, you can use that same key but if you want to deploy to another EVM network like the Binance Smart Chain, you'll need to create an account on the explorer of that network and repeat the process (but replace "etherscan" with the name of the explorer).

For example, for the Binance Smart Chain you would need to create an account on bscscan.com.

Now, to verify your smart contract, run this command:

npx hardhat verify --network <your-network> <contract-address>

and of course, replace <your-network> with the network that you deployed your smart contract to and <contract-address> with the address of your smart contract.

How to verify your smart contract on Etherscan using Brownie

Just like with Hardhat, once your smart contract, you need to create an Etherscan account here: https://etherscan.io/register

Once it's done, go to the "API Keys" section on your profile page. There you can create a new API Key and copy it.

In your .env file, you need to add this line and paste your Etherscan API Key:

export ETHERSCAN_TOKEN=YOUR-API-KEY-HERE

And in the Brownie config file brownie-config.yaml, you'll need to link to that environment at the root level of the config file:

// ... rest of the file
dotenv: .env
// ... rest of the file

Then in your script, you need to pass publish_source=True to the deploy function:

contract = MyContract.deploy({"from": account}, publish_source=True)

If the contract is already deployed, you can have it verified by running this in a Python script file:

contract = MyContract.at("ADDRESS-OF-CONTRACT-HERE")
MyContract.publish_source(contract)

Again here, you'll need to put the address of your own contract.

If you want to verify a smart contract deployed on other EVM networks, you can follow the same process but instead of using Etherscan, you'll use the blockchain explorer of the network you're using. For example, on the Binance Smart Chain it's bscscan.com.

How to verify your smart contract on Etherscan using their interface

Here it can get a bit tricky. If you want to verify your contract directly on the website, without using Brownie or Hardhat, you'll need to upload the smart contract source code files.

For that, go to the Etherscan page of your smart contract by searching for its address in the search bar. From there, you can click on the "Contract" tab and then on the "Verify" link.

They will ask you to upload all the Solidity source code files. If your smart contract has multiple files, you'll have to upload everything. Make sure to set the correct Solidity version. Enabling optimization is recommended as well.

How to check that the smart contract is verified on Etherscan

To check that your smart contract is verified on Etherscan, go to the page of your smart contract on Etherscan by searching for its address in the search bar.

Then on the "Contract" tab, you'll be able to see the code of your contract and interact with the functions of your smart contract in "React contract" and "write contract".

And that's it 🎉

Thank you for reading this article, if you want to go further and get better at blockchain development, leave your email below and you'll get:

  • access to the private Discord of a community of Web3 builders
  • access to free guides that will teach you a subject from scratch like the Web3 JS Cheat Sheet