Different bytecodes when verifying contract on Etherscan Goerli for code from OpenZeppelin Wizard

I went to https://wizard.openzeppelin.com to generate an ERC20 contract and then pasted the contract on Remix and deployed on Goerli. Then, I flattened the same code and tried to verify it on Goerli with the deployed contract but it says...

Compiler debug log:
 Error! Unable to generate Contract Bytecode and ABI
 Found the following ContractName(s) in source code : Context, ECDSA, EIP712, ERC20, ERC20Burnable, ERC20Pausable, ERC20Permit, IERC1155Errors, IERC20, IERC20Errors, IERC20Metadata, IERC20Permit, IERC5267, IERC721Errors, Math, MessageHashUtils, MyToken, Nonces, Ownable, Pausable, ShortStrings, SignedMath, StorageSlot, Strings
 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 

I compared the bytecodes - the bytecode (what we are looking for) - vs what we got - and they don't match. I even compared the byte code from Remix with the one generated by Etherscan and they still don't match. How come?

I chose to compile and deploy the unflattened code and used the flattened version on Etherscan verification but I thought they should match up, shouldn't they?

I also set the same compiler version and turned on optimization.

Below is the ERC20 code I used from OpenZeppelin Wizard. And the contract on Goerli is https://goerli.etherscan.io/address/0xb1f46ef6ac42e15f7a8bb0cf272ac0b49dbe5204

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.20;
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
    import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";
    import "@openzeppelin/contracts/access/Ownable.sol";
    import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
    contract MyToken is ERC20, ERC20Burnable, ERC20Pausable, Ownable, ERC20Permit {
        constructor(address initialOwner)
            ERC20("MyToken", "MTK")
        function pause() public onlyOwner {
        function unpause() public onlyOwner {
        function mint(address to, uint256 amount) public onlyOwner {
            _mint(to, amount);
        // The following functions are overrides required by Solidity.
        function _update(address from, address to, uint256 value)
            override(ERC20, ERC20Pausable)
            super._update(from, to, value);

I tried compiling and deploying the flattened code and verification still failed. I went to https://abi.hashex.org/ and entered my ABI and the encoded data matches the one generated by Goerli.

I was using paris EVM. When I went to use shanghai EVM without optimization, it worked. How come?

Sorry. I solved it. Thank u!

1 Like