Skip to content

Fix hardhat-ledger in some chains #6398

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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/silver-kids-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/hardhat-ledger": patch
---

Fix hardhat-ledger when eth_accounts isn't available.
19 changes: 18 additions & 1 deletion packages/hardhat-ledger/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,20 @@ export class LedgerProvider extends ProviderWrapperWithChainId {
}

if (args.method === "eth_accounts") {
const accounts = (await this._wrappedProvider.request(args)) as string[];
// some rpcs return "the method has been deprecated: eth_accounts" error
let accounts: string[];
try {
accounts = (await this._wrappedProvider.request(args)) as string[];
} catch (error) {
if (
error instanceof Error &&
error.message.includes("deprecated: eth_accounts")
) {
accounts = [];
} else {
throw error;
}
}
return [...accounts, ...this.options.accounts];
}

Expand Down Expand Up @@ -305,6 +318,10 @@ export class LedgerProvider extends ProviderWrapperWithChainId {
if (txRequest.data !== undefined) {
baseTx.data = toHex(txRequest.data);
}
// force legacy tx type if EIP-1559 fields are not present
if (!hasEip1559Fields) {
baseTx.type = 0;
}

const txToSign =
ethers.Transaction.from(baseTx).unsignedSerialized.substring(2);
Expand Down
Loading