# Verify an initializer upgradeable contract on Etherscan

**URL:** <https://forum.openzeppelin.com/t/verify-an-initializer-upgradeable-contract-on-etherscan/33370>\
**Category:** Smart Contracts\
**Tags:** etherscan-verify\
**Created:** [November 27, 2022, 7:36am UTC](https://forum.openzeppelin.com/t/verify-an-initializer-upgradeable-contract-on-etherscan/33370 "2022-11-27T07:36:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Showen\_Peng](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@Showen\_Peng](https://forum.openzeppelin.com/u/Showen_Peng)\
**Post date:** [November 27, 2022, 7:36am UTC](https://forum.openzeppelin.com/t/verify-an-initializer-upgradeable-contract-on-etherscan/33370/1 "2022-11-27T07:36:45Z")

</div>

#### Fatory.sol

```auto
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.9;

import "./interfaces/IFactory.sol";
import "./Pair.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract Factory is IFactory, Initializable {
    mapping(address => mapping(address => address)) public override getPair;
    address[] public override allPairs;

    uint32 public override feeArg;
    address public override feeTo;
    address public override feeToSetter;
    address public override twammAdd;

    constructor(address _feeToSetter) {
        feeToSetter = _feeToSetter;
    }

    function allPairsLength() external view override returns (uint256) {
        return allPairs.length;
    }

    function initialize(address _twammAdd) external override initializer {
        twammAdd = _twammAdd;
    }

    function createPair(
        address token0,
        address token1
    ) external override returns (address pair) {
        require(
            msg.sender == twammAdd,
            "Invalid User, Only TWAMM Can Create Pair"
        );
        require(twammAdd != address(0), "Factory Not Initialized By TWAMM Yet");
        require(token0 != token1, "Factory: Identical Addresses");

        (address tokenA, address tokenB) = token0 < token1
            ? (token0, token1)
            : (token1, token0);
        require(tokenA != address(0), "Factory: Zero Address");
        require(getPair[tokenA][tokenB] == address(0), "Factory: Pair Exists"); // single check is sufficient

        bytes memory bytecode = type(Pair).creationCode;
        bytes memory bytecodeArg = abi.encodePacked(
            bytecode,
            abi.encode(tokenA, tokenB, twammAdd)
        );
        bytes32 salt = keccak256(abi.encodePacked(tokenA, tokenB));
        assembly {
            pair := create2(0, add(bytecodeArg, 0x20), mload(bytecodeArg), salt)
        }
        require(pair != address(0), "Create2: Failed On Deploy");
        getPair[tokenA][tokenB] = pair;
        getPair[tokenB][tokenA] = pair; // populate mapping in the reverse direction
        allPairs.push(pair);
        emit PairCreated(tokenA, tokenB, pair, allPairs.length);
    }

    function setFeeArg(uint32 _feeArg) external override {
        require(msg.sender == feeToSetter, "Factory: Forbidden");
        feeArg = _feeArg;
    }

    function setFeeTo(address _feeTo) external override {
        require(msg.sender == feeToSetter, "Factory: Forbidden");
        feeTo = _feeTo;
    }

    function setFeeToSetter(address _feeToSetter) external override {
        require(msg.sender == feeToSetter, "Factory: Forbidden");
        feeToSetter = _feeToSetter;
    }
}

```

Hello everyone,

I managed to create an upgradable contract (Factory.sol) and deploy it to the mainnet ([https://etherscan.io/address/0x408f66057163d829a30D4d466092c6B0eebb692f](https://etherscan.io/address/0x408f66057163d829a30D4d466092c6B0eebb692f)) with hardhat.

I then did a fine job of upgrading Factory.sol using the `@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol` contract. The twammAdd is [https://etherscan.io/address/0xcd43AbA971bEF65555D877657F83093dDFB885b8](https://etherscan.io/address/0xcd43AbA971bEF65555D877657F83093dDFB885b8)

```auto
function initialize(address _twammAdd) external override initializer {
        twammAdd = _twammAdd;
    }

```

Now, I’m now trying to verify it manually on etherscan with the command: `npx hardhat verify --contract "contracts/Factory.sol: Factory" --network mainnet 0x408f66057163d829a30D4d466092c6B0eebb692f "0xCB3A9BFC9f99E75E922a516EED04D9F62e83a28E"`, but I got the error:

> Error in plugin @nomiclabs/hardhat-etherscan: The address provided as an argument contains a contract, but its bytecode doesn't match the contract contracts/Factory.sol: Factory.

Who can help verify this contract to etherscan? Thanks!

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [November 28, 2022, 3:06am UTC](https://forum.openzeppelin.com/t/verify-an-initializer-upgradeable-contract-on-etherscan/33370/2 "2022-11-28T03:06:23Z")

</div>

You need to provide the parameter for `constructor` rather than `initialize`, it seems like `_feeToSetter` address is `0xCB3A9BFC9f99E75E922a516EED04D9F62e83a28E`.

---

<div class="post-metadata">

**Author:** ![Showen\_Peng](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@Showen\_Peng](https://forum.openzeppelin.com/u/Showen_Peng)\
**Post date:** [November 28, 2022, 3:14am UTC](https://forum.openzeppelin.com/t/verify-an-initializer-upgradeable-contract-on-etherscan/33370/4 "2022-11-28T03:14:09Z")

</div>

Hi,I wrote the wrong address before, `npx hardhat verify --contract "contracts/Factory.sol: Factory" --network mainnet 0x408f66057163d829a30D4d466092c6B0eebb692f "0xCB3A9BFC9f99E75E922a516EED04D9F62e83a28E"` is also useless.

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [November 28, 2022, 6:30am UTC](https://forum.openzeppelin.com/t/verify-an-initializer-upgradeable-contract-on-etherscan/33370/5 "2022-11-28T06:30:08Z")

</div>

I do not have the source code, so I can not verify for you, maybe you can have a look at the hardhat docs: [hardhat-etherscan | Hardhat](https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-etherscan)

---

<div class="post-metadata">

**Author:** ![Showen\_Peng](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@Showen\_Peng](https://forum.openzeppelin.com/u/Showen_Peng)\
**Post date:** [November 28, 2022, 6:36am UTC](https://forum.openzeppelin.com/t/verify-an-initializer-upgradeable-contract-on-etherscan/33370/6 "2022-11-28T06:36:26Z")

</div>

[https://github.com/PulsarSwap/TWAMM-Contracts/blob/master/contracts/Factory.sol](https://github.com/PulsarSwap/TWAMM-Contracts/blob/master/contracts/Factory.sol)  
This is our repo, thanks!

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [November 28, 2022, 3:40pm UTC](https://forum.openzeppelin.com/t/verify-an-initializer-upgradeable-contract-on-etherscan/33370/7 "2022-11-28T15:40:32Z")

</div>

Have a try, but failed.

```auto
npx hardhat verify --network mainnet DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"

```

---

<div class="post-metadata">

**Author:** ![Showen\_Peng](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@Showen\_Peng](https://forum.openzeppelin.com/u/Showen_Peng)\
**Post date:** [November 29, 2022, 1:55am UTC](https://forum.openzeppelin.com/t/verify-an-initializer-upgradeable-contract-on-etherscan/33370/8 "2022-11-29T01:55:34Z")

</div>

I called the initialize() function after deploying the Factory.sol contract and was unable to verify

---

<div class="post-metadata">

**Author:** ![Showen\_Peng](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@Showen\_Peng](https://forum.openzeppelin.com/u/Showen_Peng)\
**Post date:** [November 29, 2022, 9:44am UTC](https://forum.openzeppelin.com/t/verify-an-initializer-upgradeable-contract-on-etherscan/33370/9 "2022-11-29T09:44:17Z")

</div>

Can you help me with this problem? I can pay you for it.

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [November 30, 2022, 10:09am UTC](https://forum.openzeppelin.com/t/verify-an-initializer-upgradeable-contract-on-etherscan/33370/10 "2022-11-30T10:09:51Z")

</div>

I tried to verify contracts at the mater branch, but it failed, so maybe this is not the source contract to deploy.
