Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't check that address is a contract in getContractAt #3301

Merged
merged 2 commits into from Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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