UUPS Upgradeable ContractFactory Error: 'Initializable: contract is already initialized'

Hello,
I built a UUPS upgradeable contractFactory using the upgrades plugin, and when I try to test it or even deploy it locally, I get an error:

Error: VM Exception while processing transaction: reverted with reason string 'Initializable: contract is already initialized'

This is my deploy code:

    const VFactory = await hre.ethers.getContractFactory("VFactory");
    const vFactory = <VFactory>(
        await upgrades.deployProxy(VFactory, [av.address, wl.address], { kind: 'uups' })
    );
    console.log("VFactory deployed to:", vFactory.address)

And this is the logic contract initialize function:

function initialize(address _template, address _whitelist) initializer public {
        __ERC721_init("AW 2", "AW-V2");
        super.initialize("AW 2");
        __AccessControl_init();
        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
        require(_template != address(0), "VFactory: invalid template");
        template = _template;
        whitelist = _whitelist;
    }

One thing to note is that I have used deployProxy within this same file on several other contracts and it worked seamlessly.

Any insights are highly appreciated!

The initializer modifier can only be called once. So your parent contract and child contract cannot both have the initializer modifier if the child's initializer is calling super.initialize.

Instead, the parent contract's initialization function can use the onlyInitializing modifier.

1 Like