0
0
Blockchain / Solidityprogramming~10 mins

Contract verification on Etherscan in Blockchain / Solidity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Contract verification on Etherscan
Write Smart Contract Code
Compile Contract to Bytecode
Deploy Contract on Blockchain
Get Contract Address
Go to Etherscan Verification Page
Submit Source Code + Compiler Settings
Etherscan Compiles and Matches Bytecode
Shows the step-by-step process from writing a smart contract to verifying it on Etherscan by matching compiled bytecode.
Execution Sample
Blockchain / Solidity
pragma solidity ^0.8.0;

contract SimpleStorage {
    uint storedData;
    function set(uint x) public {
        storedData = x;
    }
}
A simple Solidity contract storing a number, ready to be compiled and deployed.
Execution Table
StepActionInput/ConditionResult/Output
1Write contract codeSimpleStorage contract codeSource code ready
2Compile contractSolidity compiler v0.8.0Bytecode generated
3Deploy contractBytecode on blockchainContract address assigned
4Open Etherscan verification pageContract address inputVerification form loaded
5Submit source code + compiler settingsSource code + compiler version + optimizationEtherscan compiles source
6Compare compiled bytecode with on-chain bytecodeBytecode match?Yes - verification success
7Verification resultSuccessContract source code published on Etherscan
💡 Verification stops after bytecode matches on-chain bytecode or fails if no match
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 5Final
source_codeSimpleStorage codeSameSameSubmitted to EtherscanPublished on Etherscan
bytecodeNoneGenerated by compilerDeployed on blockchainRecompiled by EtherscanMatched on-chain bytecode
contract_addressNoneNoneAssigned after deploymentUsed for verificationUsed for verification
Key Moments - 3 Insights
Why must the compiler version and optimization settings match exactly during verification?
Because Etherscan recompiles the source code with the provided settings and compares bytecode. If settings differ, bytecode won't match, causing verification to fail (see execution_table step 5 and 6).
What happens if the bytecode does not match during verification?
Verification fails and the source code is not published. This is shown in the concept_flow where 'No Match' leads to 'Verification Failed'.
Why do we need the contract address for verification?
The contract address tells Etherscan which on-chain bytecode to compare against the compiled source code (see execution_table step 4 and 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output after step 3 (Deploy contract)?
AContract address assigned
BSource code published
CBytecode generated
DVerification failed
💡 Hint
Check the 'Result/Output' column for step 3 in the execution_table.
At which step does Etherscan compare the compiled bytecode with the on-chain bytecode?
AStep 4
BStep 6
CStep 5
DStep 7
💡 Hint
Look for the step mentioning 'Compare compiled bytecode' in the execution_table.
If the compiler version submitted to Etherscan is different from the one used to deploy, what will happen?
AContract address will change
BVerification will succeed
CVerification will fail due to bytecode mismatch
DSource code will be automatically corrected
💡 Hint
Refer to key_moments about compiler version and optimization settings.
Concept Snapshot
Contract verification on Etherscan:
1. Write and compile smart contract.
2. Deploy contract to blockchain.
3. Get contract address.
4. Submit source code and compiler settings on Etherscan.
5. Etherscan recompiles and compares bytecode.
6. If matched, source code is published for transparency.
Full Transcript
Contract verification on Etherscan is the process of proving that the source code you wrote matches the code deployed on the blockchain. First, you write your smart contract code and compile it to get bytecode. Then you deploy this bytecode to the blockchain, which gives you a contract address. To verify, you go to Etherscan, enter the contract address, and submit your source code along with the exact compiler version and optimization settings you used. Etherscan recompiles your source code and compares the bytecode with the one on the blockchain. If they match, verification succeeds and your source code is published on Etherscan for anyone to see. This process helps users trust the contract by seeing its source code. If the bytecode does not match, verification fails. It is important to use the exact compiler settings to avoid mismatch. The contract address is needed so Etherscan knows which deployed code to compare against.