Skip to content

Commit

Permalink
fix: return no accounts if eth_accounts is deprecated
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kanej committed Aug 19, 2024
1 parent 303d697 commit 93b30d5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
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

0 comments on commit 93b30d5

Please sign in to comment.