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

fix: return no accounts if eth_accounts is deprecated #5655

Merged
merged 1 commit into from
Aug 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/popular-ways-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/hardhat-ethers": patch
---

Fix for `getSigners` against networks where `eth_accounts` is deprecated.
15 changes: 14 additions & 1 deletion packages/hardhat-ethers/src/internal/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,20 @@ function isArtifact(artifact: any): artifact is Artifact {
export async function getSigners(
hre: HardhatRuntimeEnvironment
): Promise<HardhatEthersSigner[]> {
const accounts: string[] = await hre.ethers.provider.send("eth_accounts", []);
let accounts: string[];

try {
accounts = await hre.ethers.provider.send("eth_accounts", []);
} catch (error) {
if (
error instanceof Error &&
/the method has been deprecated: eth_accounts/.test(error.message)
) {
return [];
}

throw error;
}

const signersWithAddress = await Promise.all(
accounts.map((account) => getSigner(hre, account))
Expand Down
19 changes: 19 additions & 0 deletions packages/hardhat-ethers/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ describe("Ethers plugin", function () {
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
);
});

it("should return an empty array of signers if `eth_accounts` is deprecated", async function () {
const originalSend = this.env.ethers.provider.send;

this.env.ethers.provider.send = async function (
method: string,
params: any
) {
if (method === "eth_accounts") {
throw new Error("the method has been deprecated: eth_accounts");
}

return originalSend.call(this, method, params);
};

const sigs = await this.env.ethers.getSigners();

assert.deepStrictEqual(sigs, []);
});
});

describe("getImpersonatedSigner", function () {
Expand Down