Skip to content

Commit

Permalink
Don't check that address is a contract in getContractAt
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Oct 26, 2022
1 parent 3f162e2 commit 02ebfad
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
2 changes: 0 additions & 2 deletions packages/hardhat-ethers/README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 02ebfad

Please sign in to comment.