Contract Verification on PolygonScan

Hi All,

I am trying to verify the Smart Contract 0x0b103c408845ba8db7cfcb92c7551aaf2d61ca64 on PolygonScan

I flatten the .sol file and I used to implement the contract

Source code can be found here

When I pass it to the verification process with a singe file on PolygonScan it brings me this. It founds the exact code match but it is not being verifying it

1 Like

I resolved it. I copied the Bytecode paste it used the HEX data and import it. That is the solution hope it helps a lot of developers in the future.
Finally I can launch

Hello Simeon,
Could you please explain a little more about the steps for this process. I couldnt verify my contracts on ploygon



First you need to flatten you file and than you need to copy the whole code paste in as a single file and you are nearly ready.

Once you are on the remix or truffle you will need as well to copy the ABI hexa code.

Paste the first smart Contract and than after it the ABI code make sure the settings are the same as the compiler version.

Yeah, I had used the flattened file and Im getting the same error as yours. Im using hardhat to compile and deploy.
But Im confused where to paste the ABI and where and how I should use the

1 Like

Hey @Shinoy_K, not sure if you're still having this error. This thread helped me solve this issue. The error: But we were unable to locate a matching bytecode (err_code_2) was occurring because I was trying to verify a contract that was deployed by another contract. In order to properly verify this contract I had to input the ABI encoded constructor parameters into the Constructor Arguments section in the contract verification form. This is right below the solidity source code input.

The tool lets you enter these arguments and it generates the ABI encoded params. I used the section underneath Or enter these parameters manually. In my case I had to encode the constructor function type. For each argument I set the type on the left side (using the dropdown) and then input the value on the right side. So if I had an argument of owner that was of type Address, I would set Address using the dropdown on the left and then paste in the actual address value that was passed in during contract creation.

Right below these inputs you will see a text box containing the ABI encoded params (a long string of numbers and letters), you can paste this into the Constructor Arguments section and it should verify the contract properly. I hope this clarification helps you or anyone else facing this issue! Thanks!

I encountered some similar issues with contract verification on Polygonscan, for a customizable ERC20 token factory that imports OpenZeppelin's ERC20. Here's a summary of what I found

I initially compiled the the contract with hardhat. In order to perform contract verification on Polygonscan, I had to flatten the import. I used the npx hardhat flatten contract.sol > output.sol command and inputted the the flattened contract, but kept getting the issue below, similar to the OP:

After numerous attempts at flattening and re-attempting verification, I realized that the entire flow would work if compiled by Remix instead of Hardhat.

So ultimately, I ended up using Remix to:

  1. recompile my token factory contract
  2. use that new ABI and bytecode instead for my token minter dapp (as the contract factory)
  3. use REMIX to flatten it
  4. complete contract verification on Polygonscan successfully

So now the verification works now because the flattened source code was generated from Remix, as was the original ABI and bytecode.

Made a video demo with my flow:

My suspicion is that there could be a discrepancy between the solidity compiler version with the OpenZeppelin contract and the actual contract when doing it with hardhat.

Other things to make sure are consistent would be the solc version, optimization, license, etc.

Hope this helps!

Thank you for sharing @juwu. Flattening is not the best way to verify a contract. If you deployed with Hardhat, did you try the hardhat-etherscan plugin? Note that despite the name it supports Polygonscan as well.

People having issues with verification should consult the main resource guide:

@frangio thanks for the reply! I haven't tried the etherscan plugin partially because the UI/website approach was the one that my users tried and flagged to me.
Also, most resources I came across suggest going the website route on etherscan/polygonscan. It'd be nice to have a standard -- either all CLI or all web

I stopped having problems checking contracts when I started using complex argument checking:

There may also be verification issues if using windows Powershell with the / symbol turning it to \

I get a same problem
Can someone help me plz