Can contracts deployed in factory mode be automatically verified?

My contract is as follows:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract ERC20Mock is ERC20 {
    uint8 private immutable decimal;

    constructor(string memory _name, string memory _symbol, uint8 _decimal) ERC20(_name, _symbol) {
        decimal = _decimal;
    }

    function mint(address _to, uint256 _amount) external {
        _mint(_to, _amount);
    }

    function decimals() public view override returns (uint8) {
        return decimal;
    }
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import {ERC20Mock} from "./ERC20Mock.sol";

contract TokenFactory {
    function CreateToken(
        string memory _name, 
        string memory _symbol, 
        uint8 _decimal
    ) external returns (address) {
        ERC20Mock newToken =  new ERC20Mock(_name,_symbol, _decimal);
        return address(newToken);
    }
}

Current situation: I have verified the TokenFactory.sol contract in etherscan. But the contract deployed by calling the CreateToken function is not automatically verified, I need to verify it manually.

My question: In the factory mode, the code of the deployed contract is already public, why doesn't etherscan automatically verify it?

In addition: What is the appropriate way to achieve automatic verification?

Thank you for any reply. :folded_hands:

Automatic verification of contracts is not possible when deployed via factory because each deployment might have different constructor arguments.
No tooling automatically “catches” these dynamic deployments unless you explicitly wire it up.

If you want to automate the verifications for factory deployments, modify your deploy scripts to emit the new smart contract address and automatically run verification commands after deployment.

I made an unexpected and pleasant discovery: Etherscan seems to automatically verify contracts with the same bytecode.

That is, when I first deploy an ERC20Mock contract using TokenFactory, the contract won't be verified. At this point, you can verify it manually. However, when you deploy the ERC20Mock contract again, it will be verified automatically.

:star_struck:

2 Likes