Skip to content

Commit 93b30d5

Browse files
committedAug 19, 2024
fix: return no accounts if eth_accounts is deprecated
Erigon now responds that `eth_accounts` is deprecated when we make an RPC call. Instead of erroring we now return an empty set of accounts from `getSigners` if `eth_accounts` is deprecated. Fixes #5572.
1 parent 303d697 commit 93b30d5

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed
 

‎.changeset/popular-ways-whisper.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomicfoundation/hardhat-ethers": patch
3+
---
4+
5+
Fix for `getSigners` against networks where `eth_accounts` is deprecated.

‎packages/hardhat-ethers/src/internal/helpers.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,20 @@ function isArtifact(artifact: any): artifact is Artifact {
4040
export async function getSigners(
4141
hre: HardhatRuntimeEnvironment
4242
): Promise<HardhatEthersSigner[]> {
43-
const accounts: string[] = await hre.ethers.provider.send("eth_accounts", []);
43+
let accounts: string[];
44+
45+
try {
46+
accounts = await hre.ethers.provider.send("eth_accounts", []);
47+
} catch (error) {
48+
if (
49+
error instanceof Error &&
50+
/the method has been deprecated: eth_accounts/.test(error.message)
51+
) {
52+
return [];
53+
}
54+
55+
throw error;
56+
}
4457

4558
const signersWithAddress = await Promise.all(
4659
accounts.map((account) => getSigner(hre, account))

‎packages/hardhat-ethers/test/index.ts

+19
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,25 @@ describe("Ethers plugin", function () {
7373
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
7474
);
7575
});
76+
77+
it("should return an empty array of signers if `eth_accounts` is deprecated", async function () {
78+
const originalSend = this.env.ethers.provider.send;
79+
80+
this.env.ethers.provider.send = async function (
81+
method: string,
82+
params: any
83+
) {
84+
if (method === "eth_accounts") {
85+
throw new Error("the method has been deprecated: eth_accounts");
86+
}
87+
88+
return originalSend.call(this, method, params);
89+
};
90+
91+
const sigs = await this.env.ethers.getSigners();
92+
93+
assert.deepStrictEqual(sigs, []);
94+
});
7695
});
7796

7897
describe("getImpersonatedSigner", function () {

0 commit comments

Comments
 (0)
Failed to load comments.