wighawag / hardhat-deploy-ethers

MIT License
69 stars 25 forks source link

getContractAt error when using hardhat-deploy external artifacts #15

Closed maAPPsDEV closed 3 years ago

maAPPsDEV commented 3 years ago

User Story

A harhat plugin - hardhat-deploy provides very useful features that help developers working with hardhat. You can configure external artifacts in order to retrieve a contract instance that might not be related to the current project. As a user, I want to get the external contract instance by using getContractAt with the name (not ABI) which is configured in the external artifacts.

Description

For instance, let's assume you are building a very abstracted dex protocol that can interacts any kind of AMM such as uniswap. You may need to load UniswapV3Factory factory for your tests, in that case, you don't need to bring uniswap's artifacts into your project manually, because uniswap exports their artifacts via npm.

Then, you will add a notation inside hardhat.config.js as following:

{
  external: {
    contracts: [
      {
        artifacts: "node_modules/@uniswap/v3-core/artifacts",
      },
    ],
  }
}

(See details here)

And then, you will try to get UniswapV3Factory contract as following:

const factory = await ethers.getContractAt("UniswapV3Factory", "0x1F98431c8aD98523631AE4a59f267346ea31F984");

But it give you an error like:

     HardhatError: HH700: Artifact for contract "UniswapV3Factory" not found.
      at Artifacts._getArtifactPathFromFiles (node_modules/hardhat/src/internal/artifacts.ts:394:13)
      at Artifacts._getArtifactPath (node_modules/hardhat/src/internal/artifacts.ts:317:27)
      at Artifacts.readArtifact (node_modules/hardhat/src/internal/artifacts.ts:51:9)
      at Object.getContractAt (node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:401:22)
      at Context.<anonymous> (scripts/integrated/stake.spec.ts:68:24)