Verify ERC20 token on Etherscan that was deployed through Remix: Step by Step Guide

At the previous tutorial: Create an ERC20 using Remix, without writing Solidity, we have learned how to deploy contracts with the Remix, and now in this tutorial, we will learn how to verify the deployed contracts by a single file.

Cause many people deploy contracts by the Remix, so in this part, we will use the plugin FLATTENER in the Remix to help us to package all contracts file into a single file to verify.

In short, all steps are:

  1. Compile contract
  2. Flatten contract
  3. Copy the whole code to verify on the Etherscan

Okay, next let us go through it step by step.

Compile contract

I think you have followed the previous tutorial to deploy the contracts by the Remix, but you should notice the network , compiler version and compiler configuration when you deployed the contract. In this part, what you need to do is just checking the option Auto compile to compile your contract automatically, as for the another option Enable optimization , it depends on you, at here, we will use it, so all just like the following:

compiler_config

NOTICE: your contracts should be compiled without any errors.

Flattern contract

We will use the plugin FLATTENER in the Remix to flatten all contracts into a single file. Firstly, click the Plugin manager on the left side of the page, then find the plugin FLATTENER in the Inactive Modules and click the button Activate to use it, just like:

Then the plugin FLATTENER will show at the left side of the page, click it and you will find the blue button Flatten YOUR_CONTRACT.sol , click it, and then click the bottom button Save YOUR_CONTRACT_flat.sol to save the flattened file, just like following:

it will ask your permission to save file, just click the Accept , it will show File saved , so click on the option in the upper left corner File explorers and then you will find the flattened file at the bottom, just like

Common Errors:

Cause we have checked the option Auto compile at the step 1, so when we click the flattened contract file, it will compile automatically. What we need to do is solving the errors after compiling if has. Generally, we will encounter the following two errors:

One is:

ParserError: Multiple SPDX license identifiers found in source file. Use "AND" or "OR" to combine multiple licenses. Please see https://spdx.org for more information. --> contracts/OpenZeppelin.sol

For the current version, you need to remove the duplicate SPDX license manually, only keep one valid SPDX license. Here is some discussion of the issue: Deduplicate or remove SPDX license identifier comments

The other one is:

TypeError: Definition of base has to precede definition of derived contract --> OpenZeppelin_flat.sol:506:30: | 506 | abstract contract Ownable is Context { | ^^^^^^^

As for this, you should adjust the order of the contracts, that is putting the parent contract in front, and put child contract behind.
For example: the wrong code is:

abstract contract Ownable is Context{}
contract Context{}

The right order should be:

contract Context{}
abstract contract Ownable is Context{}

Here is an issue on the github about this error: Wrong contract order

Verify on the Etherscan

Nice! we are only one step away from success. Find the contract you have deployed on the Etherscan, click the option Contract and then click Verify and Publish , just like following:

Choose the right Compiler Type : Solidity(Single file)
Choose the right Compiler Version : YOUR_DEPLOYED_VERSION
Choose a right License Type .
just like following:

Click the button Continue to enter the next page, click the Optimization if you use it when you deploy, and then paste the flattened source code. Generally, Etherscan will upload constructor arguments automatically, but some times it will upload the wrong constructor arguments due to your constructor arguments are a little complex, so in this case, you can encode arguments by this tool: https://abi.hashex.org/ (if you do not know how to use it, you can have a look at this Verify Timelock contract on BSC | OpenZeppelin Community @Bsc_Talk, thanks for your detailed explanation) Finally, click the button Verify and Publish , just like following:

After waiting for a while, you can find out your contract has been verified successfully, congratulations! Like following:

This really has so many steps to do by this way, so I recommend you to read this tutorial to verify your contract:

2 Likes
Problem verifying contract on BSC Scan
Unable to generate Contract ByteCode and ABI. Changed code
Can not verify contracts on the BSC-Chain!
I can't verify my contract on BSCScan
How to verify multi-file ERC20 contract importing other files
Smarct contract verfiy
Verify contracts encounter errors
Can't verify contract on BSC scan
Unable to generate Contract ByteCode and ABI • BSC
Flattened BSC contract ERROR
Help verifying token on bscscan
BSCSCAN - Compiler debug log: Error! Unable to generate Contract ByteCode and ABI
Error! Invalid constructor arguments provided. Please verify that they are in ABI-encoded format
Wizard + Remix + Ethereum combination needs improvement
How to verify contracts on the BSC
Error! Unable to generate Contract ByteCode and ABI ( BSC VERIFY)
Can not verify contracts
Error! Unable to generate Contract ByteCode and ABI
Help with verification on bscscan.com
File import callback not supported Context.sol
Unable to verify contract on Binance smart chain testnet (BSC testnet)
How to deplay FuturovGovernanceToken?
Error! Unable to generate Contract ByteCode and ABI - BscScan Testnet
ParserError: Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported
I need simple ERC20 token template with pramga version 0.8.0 and up
ERC20 dividend token verify failed
ERC20 Etherscan Contract Verification Failed
BscScan : Unable to verify my contract, I need help
How to verify a contract on Etherscan/BscScan/PolygonScan
Bsc Contract Won't Verify, Please Help
Contract verification
I am unable to to verify my contract on Ropsten testnet
Verify openzippelin code on BSCscan
Help, unable to generate contract bytecode and ABI
I cant verify my contract on BSCScan
ERROR AS I TRY TO VERIFY and publish MY CONTRACT
Can not verify erc20 contract in bsc scan
Can't verify contract on BSC scan
Error! Unable to generate Contract ByteCode and ABI (General Exception, unable to get compiled [bytecode])
Verify Timelock contract on BSC
Help Verifying BSC smart contract on BSCScan
Smart contract verification
Deploy a simple ERC20 token in Remix
ABI Encode Etherscan Verification Issue (err_code_2)
Smart contract verification issue in bscscan
Hello. Can anyone help me to verify my contract?
Can't verify contract on BSC scan
How to verify this smart contract?
hello i have an error when using remix with flattener
Problem when Verifying and publishing an ERC20 tokencontract on etherscan Error! Unable to generate Contract ByteCode and ABI
Need Help verify & Publish Contract Source Code
Etherscan verification for flattened contract deployed with Remix
Can't Verify Contract - Never saw this error
Need help verifying contract on Etherscan
Can't verify the contract at ftmscan
Bscscan Verification Error
Need help verifying contract on Etherscan
Help for verify on BSCscan
How to verify Simple Crowdsale?
Need help to verify contract
Can't verify contract on BSC scan
Unable to get encoded ABI to verify Contract on BscScan
How to verify a contract deployed using Remix importing OpenZeppelin via GitHub?
Hi guys ! Error with publish&verify ABI on BscScan
Cant publish a contract on bianance chain (bytecode/abi error)
Can't verify smart contract on Bscscan
Can't verify BSC contract and it has the same output
Problem when Verifying and publishing an ERC20 tokencontract on etherscan Error! Unable to generate Contract ByteCode and ABI

this is gold! Thank you so much!

1 Like

awesome!!!

I verified my contract now it`s checked green, i sign the contract, but i have this exclamation mark right next to Solidity Compiler Bugs:

Compiler specific version warnings:

The compiled contract might be susceptible to ABIDecodeTwoDimensionalArrayMemory (very low-severity), KeccakCaching (medium-severity), EmptyByteArrayCopy (medium-severity), DynamicArrayCleanup (medium-severity), MissingEscapingInFormatting (very low-severity), ImplicitConstructorCallvalueCheck (very low-severity), TupleAssignmentMultiStackSlotComponents (very low-severity), MemoryArrayCreationOverflow (low-severity), privateCanBeOverridden (low-severity) Solidity Compiler Bugs.

Now i seen other important Tokens that have this sorts of issues, now the question is : is this important for me to solve ? and if it is , how can i solve it? any hint would be great, thank you all!

Seems like you got some warings, I think you can follow the prompts to modify if it has. And some warings just wants to remind you know what are doing. Eg: it may say: loop to deep and may cost all gas, so you need to notice the length to loop. But actually for your contract, it just has two elements to loop. Anyway, you should know what dose this waring mean, and judge for yourself if it will affect you.

hi, you can help me?, i have two questions, first
how is the correct order in the contrascts than i need to solve this error:

TypeError: Definition of base has to precede definition of derived contract → OpenZeppelin_flat.sol:506:30: | 506 | abstract contract Ownable is Context { | ^^^^^^^ )

second: i do a ERC20 token in the mainnet network of matic as like this Create an ERC20 using Remix, without writing Solidity in this form of create the token i need to give ABI-encoded Constructor Arguments to verify? if the request is yes, ¿how i get that ABI-encoded Constructor Arguments?

PS: i need to add libraries here if the code is flatted ?

Hi, welcome! :wave:

Just adjust the position of the two contracts, eg:

contract Ownable is Context {}

contract Context {}

maybe you will get errors from above contracts, because your Ownable contract is inherited from contract Context, but it is defined after Ownable, so just place the Context in front, so it should be

contract Context {}

contract Ownable is Context {}

If your contract has constructor parameters, you need to encode, and you can use this tool: https://abi.hashex.org/ if not, do nothing.

thanks for you request Skyge

Having issues solving the following,

TypeError: Definition of base has to precede definition of derived contract → BEP-201_flat.sol:42:29: | 42 | interface IERC20Metadata is IERC20 { | ^^^^^^

Just like the the prompt says, and I also answered a similar question, you should make some changes manually, now your contracts are:

contract IERC20Metadata is IERC20 {}
contract IERC20 {}

Just move the contracts to make them like:

contract IERC20 {}
contract IERC20Metadata is IERC20 {}

You are Awesome @Skyge thanks for your answer, finally was able to verify my contract :slight_smile:

2 Likes

An excellent guide to all, and for people like me that are starting to deploy and verify contracts on Etherscan, Thank you @Skyge, finally was able to verify my first contract

2 Likes

Thanks Skyge.
It’s very helpful tutorial for me as beginner.

1 Like

Hi, I did everything I could and it still doesn’t work. Could you help me?

Contract: 0xa402e9e37518c1c9e3a79d448778385a8a401f0c


// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;


import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";


contract Bitelon is ERC20 {
    constructor(uint256 initialSupply) public ERC20 ("Bitelon", "BTE") {
        _mint(msg.sender,initialSupply);
    }
}

Have you followed the guide? Where did it fail? What error did you get? Please be more specific or your questions will be flagged.

thank you guy it everything work fine

2 Likes

Thank you men . . . . . .

I have flattened the contract and checked in remix, everything ok,

I have followed the guide scrupulously

but at the time of verify and publish in the network deployed I get the following error

which is the same as the user @Devon who has solved the problem without commenting how.