diff --git a/.changeset/silver-kids-argue.md b/.changeset/silver-kids-argue.md new file mode 100644 index 0000000000..8e1af1f330 --- /dev/null +++ b/.changeset/silver-kids-argue.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/hardhat-ledger": patch +--- + +Fix hardhat-ledger when eth_accounts isn't available. diff --git a/packages/hardhat-ledger/src/provider.ts b/packages/hardhat-ledger/src/provider.ts index a315612910..79d7f77040 100644 --- a/packages/hardhat-ledger/src/provider.ts +++ b/packages/hardhat-ledger/src/provider.ts @@ -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]; } @@ -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);