dethcrypto / TypeChain

🔌 TypeScript bindings for Ethereum smart contracts
MIT License
2.76k stars 361 forks source link

[hardhat + ethers-v6]Fallback to BaseContract when using hre.ethers.getContractFactory.attach #850

Closed imckl closed 1 year ago

imckl commented 1 year ago

I'm trying to migrate hardhat to newer version with the use of ethers-v6, and then find a minor issue below (v6): image

      const create2DeployerFactory = await hre.ethers.getContractFactory('Create2Deployer', signer)
      const fallbackToBaseContract = create2DeployerFactory.attach(create2DeployerAddress)

      // excepted
      const noFallback = Create2Deployer__factory.connect(create2DeployerAddress, signer)

and v5 behavior: image

With typehint I notice that exact contract type fallbacks to BaseContract in v6, differing from v5, which infers the actual type of contract This could use Type Assertion as ActualContract, or directly use AcutalContract__Factory as workarounds, but should be nice if fixed in attach.

imckl commented 1 year ago

Sometimes contract name is fixed but not specified, eg: use const contractName = 'ActualContract' thus use getContractFactory to obtain contract instead of directly using ActualContract__Factory is a need. In the sence, contract name could be anything depending on which contract I want to deploy. Currently i'm heavily using the type assertion approach by getContractFactory.attach and those stuck the migration process. Any fix/workaround could be appreciated :)

imckl commented 1 year ago

Nvm, just found hre.ethers.getContractAt as a substitution :)