Hardhat – Error: Not Assignable to Parameter in Upgrades prepareUpgrade

hardhatopenzeppelinupgrading

I have a script that deploys a new version of my upgradeable contract for later upgrading. This was working before but now I am getting an error from typescript. Here's the script:

import { network, ethers, upgrades } from "hardhat";

const MyContract = await ethers.getContractFactory("MyContract");
const upgradeAddress = await upgrades.prepareUpgrade(
    "0x...", 
    MyContract, // error is coming from this line
    {kind: "uups"}
  );
}

This generates the following error:

Argument of type 'MyContract__factory' is not assignable to parameter of type 'ContractFactory'.
  The types returned by 'deploy(...)' are incompatible between these types.
    Type 'Promise<MyContract>' is not assignable to type 'Promise<Contract>'.
      Type 'MyContract' is not assignable to type 'Contract'.
        Types of property 'connect' are incompatible.
          Type '(signerOrProvider: string | Signer | Provider) => MyContract' is not assignable to type '(signerOrProvider: string | Provider | Signer) => Contract'.
            Types of parameters 'signerOrProvider' and 'signerOrProvider' are incompatible.
              Type 'string | Provider | Signer' is not assignable to type 'string | Signer | Provider'.
                Type 'Signer' is not assignable to type 'string | Signer | Provider'.

...

No quick fixes available

Best Answer

You can take a look at this if it helps. One possible solution is to import type { ContractFactory } from 'ethers' and cast the result of ethers.getContractFactory() to ContractFactory:

https://github.com/NomicFoundation/hardhat/issues/2148

Related Topic