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.

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/ 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:

1 Like

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 {}