Skip to content

Commit

Permalink
Merge pull request #3301 from NomicFoundation/remove-get-contract-at-…
Browse files Browse the repository at this point in the history
…check

Don't check that address is a contract in getContractAt
  • Loading branch information
fvictorio committed Oct 27, 2022
2 parents 09d164e + 136f25a commit 30f4cd3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-camels-peel.md
@@ -0,0 +1,5 @@
---
"@nomiclabs/hardhat-ethers": patch
---

`getContractAt` doesn't throw anymore if the given address is not a contract.
2 changes: 0 additions & 2 deletions packages/hardhat-ethers/README.md
Expand Up @@ -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.
Expand Down
7 changes: 0 additions & 7 deletions packages/hardhat-ethers/src/internal/helpers.ts
Expand Up @@ -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);

Expand Down
8 changes: 3 additions & 5 deletions packages/hardhat-ethers/test/index.ts
Expand Up @@ -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 () {
Expand Down

0 comments on commit 30f4cd3

Please sign in to comment.