Skip to Content
CoursesEthereum Course 2025Project: ERC20 Token SaleBlock Explorers and Source Code Verification

Verify on Etherscan

View the Full Course Now 

One thing that comes up every now and then is

  1. how to verify smart contracts on block explorers
  2. why verify them in the first place
  3. how to directly interact with smart contracts using the Etherscan interface.

Why Verify Smart Contracts

First and foremost, in an open society that fosters transparency, it is considered good practice to open source the source code. Your bytecode is there anyways. But having the source code there is an additional step towards transparency.

In a world where smart contracts can handle multiple millions of dollars, its hard to justify for the wider public to interact with smart contracts if they can’t be verified.

Verifying smart contracts also lets other easier interact with them, as you’ll see in a second.

But how to go about that?

How to Verify A Smart Contract manually on Etherscan

Let’s run with a sample smart contract

//SPDX-License-Identifier: MIT pragma solidity 0.8.16; contract MyContract { mapping(address => uint) public balance; constructor() { balance[msg.sender] = 100; } function transfer(address to, uint amount) public { balance[msg.sender] -= amount; balance[to] += amount; } function someCrypticFunctionName(address _addr) public view returns(uint) { return balance[_addr]; } }

Step by step:

  1. Sign in to Etherscan

ethereum-blockchain-developer-image

  1. If you don’t have an account, you need to signup first

ethereum-blockchain-developer-image

  1. It requires an email address

ethereum-blockchain-developer-image

  1. Checks for the robot…

ethereum-blockchain-developer-image

  1. … and create an account

ethereum-blockchain-developer-image

  1. Then sign in, same here, robot check

ethereum-blockchain-developer-image

  1. And Login

ethereum-blockchain-developer-image

  1. Let’s head over to Remix, open a new Tab

ethereum-blockchain-developer-image

  1. Create a new file

ethereum-blockchain-developer-image

  1. Add the contract from above

ethereum-blockchain-developer-image

  1. make sure its the contract

ethereum-blockchain-developer-image

  1. Head over to the Deploy & Run Transaction Tab

ethereum-blockchain-developer-image

  1. Select the MetaMask injected web3 provider

ethereum-blockchain-developer-image

  1. If your MetaMask is locked, then unlock it first

ethereum-blockchain-developer-image

  1. Click ā€œDEPLOYā€

ethereum-blockchain-developer-image

  1. Click ā€œConfirmā€

ethereum-blockchain-developer-image

  1. Click ā€œView on Etherscanā€ to open the transaction on Etherscan

ethereum-blockchain-developer-image

  1. Click on the new Contract (the address) to open the contract

ethereum-blockchain-developer-image

  1. Then click on the Contract - you see its just bytecode there. Etherscan can’t guess your interface, your function names, nothing.
Function names

Sometimes Etherscan infers a function name. That is, for interfaces from known contracts, like the ERC20 contract. If you interact with this smart contract and use the transfer function, Etherscan would probably show you correctly that the function ā€œtransferā€ was used. But if you use the function someCrypticFunctionName it would just show you the 4 byte hashed function signature.

ethereum-blockchain-developer-image

  1. That’s the unverified bytecode

ethereum-blockchain-developer-image

  1. Let’s verify that Smart Contract now! Click ā€œVerify and Publishā€

ethereum-blockchain-developer-image

  1. There are two things to select: The compiler and the license

ethereum-blockchain-developer-image

  1. Select Solidity single-file from the compiler

You will later see that we can automate the source code verification with scripts from Truffle, Hardhat and Foundry. But, as you’re an Ethereum developer, its good practice to have that done at least once manually…

ethereum-blockchain-developer-image

  1. Once you select Solidity, another dropdown will appear for the compiler version

ethereum-blockchain-developer-image

  1. Select 0.8.16, or whatever compiler you used for your contract…

ethereum-blockchain-developer-image

  1. I’m licensing this contract as MIT - select the correct license here.

ethereum-blockchain-developer-image

  1. You see there are a ton of licenses. That might be parsed in later versions directly from the source code file.
SPDX License Identifier

That identifier wasn’t always in there. So, naturally, not all tools are using this identifier to determine the license.

ethereum-blockchain-developer-image

  1. Let’s continue now and see what happens!

ethereum-blockchain-developer-image

  1. We need to copy the source code from Remix into the source code field

ethereum-blockchain-developer-image

  1. Head back to Remix, copy the Source code

ethereum-blockchain-developer-image

  1. And paste the source code

ethereum-blockchain-developer-image

  1. Sometimes you need to specify the compiler optimizations. To check if you had any, head back to Remix, and click ā€œAdvanced Configurationsā€ in the compiler plugin

ethereum-blockchain-developer-image

  1. If this checkbox is checked, then set the appropriate optimizations in Etherscan as well

ethereum-blockchain-developer-image

  1. Finally, our Bytecode

ethereum-blockchain-developer-image

  1. And the ABI Array

ethereum-blockchain-developer-image

  1. All green!

ethereum-blockchain-developer-image

  1. It should say something like ā€œSuccessfully generated ByteCode and ABI for Contract Address ā€

ethereum-blockchain-developer-image

  1. ā€œContractABI:ā€

ethereum-blockchain-developer-image

  1. Click on your contract address to get back

ethereum-blockchain-developer-image

  1. Click ā€œContractā€ - which now has a little check next to it

ethereum-blockchain-developer-image

  1. Click ā€œRead Contractā€

ethereum-blockchain-developer-image

  1. You see, now you have even the most crypto function names as cleartext here to interact with.

ethereum-blockchain-developer-image

  1. Let’s interact with our smart contract. Click ā€œWriteā€

ethereum-blockchain-developer-image

  1. Click ā€œConnect to Web3ā€

ethereum-blockchain-developer-image

  1. Confirm the dialog box

ethereum-blockchain-developer-image

  1. Select ā€œMetaMaskā€ from the options

ethereum-blockchain-developer-image

  1. Select ā€œAccount 1ā€ to connect

ethereum-blockchain-developer-image

  1. Click ā€œNextā€

ethereum-blockchain-developer-image

  1. Click ā€œConnectā€

ethereum-blockchain-developer-image

  1. Click ā€œ1. transferā€

ethereum-blockchain-developer-image

  1. Let’s copy the second address from MetaMask…

ethereum-blockchain-developer-image

  1. Click here:

ethereum-blockchain-developer-image

  1. Click ā€œ0.4897ā€

ethereum-blockchain-developer-image

  1. Click ā€œAccount 2 0x99b…d4F6ā€

ethereum-blockchain-developer-image

  1. Click ā€Ā  amount (uint256)ā€

ethereum-blockchain-developer-image

  1. Click ā€œWriteā€

ethereum-blockchain-developer-image

  1. Click ā€œConfirmā€

ethereum-blockchain-developer-image

  1. Click ā€œRead Contractā€

ethereum-blockchain-developer-image

  1. Now lets read out the balance. Click ā€œ1. balanceā€ and paste in the same account that we used for transferring the funds to

ethereum-blockchain-developer-image

  1. And simple click ā€œQueryā€

ethereum-blockchain-developer-image

It should show you ā€œ1ā€ as balance.

Last updated on