tokenethereumsmartcontractshardhatetherscan

Problem with verifying token smart contract on Etherscan


I have made my first token smart contract and I deployed it on Sepolia testnet using Infura Web3 API, now the problem is I can't verify the contract through Etherscan, it asks me for the solidity smart contract code, but the source code needs to be "flattened" in order to work as it contains inheritance form the ERC20 smart contract (based on my search). How can I get the correct source code and constructor arguments?

I used VS code to write the solidity smart contract and hardhat to deploy it into the Infura Gateway. Here is the project repo: https://github.com/youssef-elharty/TofuToken

I tried uploading the contract code into Remix IDE to flatten it using the flatten tool, but the bytecode is not matching the deployed contract and it says that the SPDX License Identifier is not provided, I used constructor arguments in deployment and the ABI is 00000000000000000000000000000000000000000000000000000000009896800000000000000000000000000000000000000000000000000000000000000032

Compiler debug log:

Error! Unable to generate Contract ByteCode and ABI
 Found the following ContractName(s) in source code : Context, ERC20, ERC20Burnable, ERC20Capped, IERC20, IERC20Metadata, TofuToken
 But we were unable to locate a matching bytecode (err_code_2)
 For troubleshooting, you can try compiling your source code with the Remix - Solidity IDE and check for exceptions

Compiler Warning(s):

Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> myc

Compiler Version: v0.8.17+commit.8df45f5f Optimization Enabled: True Runs: 200

ByteCode (what we are looking for):
60a06040523480156200001157600080fd5b5060405162002b9b3803806...

-vs what we got-

We tried looking for a match from the list of compiled contract bytecode outputs (as listed below), but was unable to find an exact match.

1)ERC20
//long ByteCode
2)TofuToken
//long Bytecode

Solution

  • Flattening is the process of compiling all your source code into one file — which we don't recommend as it makes files hard to read.

    Since you are using Hardhat, there is a plugin that helps you with submitting verifications to Etherscan!