From 02ebfade2821d43a9b7592b8f6d4e2490fd24b05 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 26 Oct 2022 19:05:40 +0200 Subject: [PATCH] Don't check that address is a contract in getContractAt --- packages/hardhat-ethers/README.md | 2 -- packages/hardhat-ethers/src/internal/helpers.ts | 7 ------- packages/hardhat-ethers/test/index.ts | 8 +++----- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/hardhat-ethers/README.md b/packages/hardhat-ethers/README.md index cec2d45aa5..8ad4cda2b9 100644 --- a/packages/hardhat-ethers/README.md +++ b/packages/hardhat-ethers/README.md @@ -81,8 +81,6 @@ The [`Contract`s](https://docs.ethers.io/v5/single-page/#/v5/api/contract/contra If there is no signer available, `getContractAt` returns [read-only](https://docs.ethers.io/v5/single-page/#/v5/api/contract/contract/-%23-Contract--readonly) contracts. -If the address provided to `getContractAt` is not the address of a contract account, an error will be thrown. - ## Usage There are no additional steps you need to take for this plugin to work. diff --git a/packages/hardhat-ethers/src/internal/helpers.ts b/packages/hardhat-ethers/src/internal/helpers.ts index 22e421ef69..1963c1b9ef 100644 --- a/packages/hardhat-ethers/src/internal/helpers.ts +++ b/packages/hardhat-ethers/src/internal/helpers.ts @@ -303,13 +303,6 @@ export async function getContractAt( address: string, signer?: ethers.Signer ) { - if ((await hre.ethers.provider.getCode(address)) === "0x") { - throw new NomicLabsHardhatPluginError( - pluginName, - `${address} is not a contract account.` - ); - } - if (typeof nameOrAbi === "string") { const artifact = await hre.artifacts.readArtifact(nameOrAbi); diff --git a/packages/hardhat-ethers/test/index.ts b/packages/hardhat-ethers/test/index.ts index 8ab7ee4a19..c2ed5747a7 100644 --- a/packages/hardhat-ethers/test/index.ts +++ b/packages/hardhat-ethers/test/index.ts @@ -710,12 +710,10 @@ describe("Ethers plugin", function () { }); describe("by name and address", function () { - it("Should throw if address does not belong to a contract", async function () { + it("Should not throw if address does not belong to a contract", async function () { const address = await signers[0].getAddress(); - return assert.isRejected( - this.env.ethers.getContractAt("Greeter", address), - `${address} is not a contract account.` - ); + // shouldn't throw + await this.env.ethers.getContractAt("Greeter", address); }); it("Should return an instance of a contract", async function () {