0
0
Blockchain / Solidityprogramming~5 mins

Contract verification on Etherscan in Blockchain / Solidity

Choose your learning style9 modes available
Introduction

Contract verification on Etherscan helps everyone see the real code behind a smart contract. It makes the contract trustworthy and easy to check.

You want others to trust your smart contract by showing its source code.
You need to debug or check your deployed contract's code on the blockchain.
You want to share your contract code publicly for transparency.
You want to interact with your contract through Etherscan's interface.
You want to prove your contract does what it says without hiding code.
Syntax
Blockchain / Solidity
1. Go to Etherscan and find your deployed contract address.
2. Click on 'Verify and Publish' tab.
3. Enter your contract's source code and compiler details.
4. Submit the form to verify your contract.
5. Wait for Etherscan to confirm verification.

You need the exact compiler version and settings used to deploy the contract.

Make sure your source code matches the deployed bytecode exactly.

Examples
This is a simple Solidity contract you might verify on Etherscan.
Blockchain / Solidity
pragma solidity ^0.8.0;

contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}
Steps to verify a contract after deployment.
Blockchain / Solidity
1. Deploy your contract using Remix or Hardhat.
2. Copy the deployed contract address.
3. On Etherscan, paste the address and start verification.
4. Provide the same Solidity code and compiler version.
5. Submit and wait for success message.
Sample Program

This is a very simple contract you can deploy and then verify on Etherscan by following the verification steps.

Blockchain / Solidity
pragma solidity ^0.8.0;

contract HelloWorld {
    string public greet = "Hello, Etherscan!";
}
OutputSuccess
Important Notes

Verification does not change the contract; it only publishes the source code.

If verification fails, check compiler version and optimization settings carefully.

Once verified, anyone can read and trust your contract code on Etherscan.

Summary

Contract verification publishes your smart contract code on Etherscan for trust and transparency.

You must use the exact compiler version and settings used during deployment.

Verification allows easy interaction and inspection of your contract by others.