Skip to content

Conversation

kanej
Copy link
Member

@kanej kanej commented Aug 1, 2025

Plugins can extend network config, but the config generated for a new network connection was missing those extensions (they where not being copied across).

This is in response to a bug booting npx hardhat node from the v3-hh-ledger branch within the example-project. If you run pnpm hardhat node you get an error:

> pnpm hardhat node                        
An unexpected error occurred:

TypeError: Cannot read properties of undefined (reading 'map')
    at new LedgerHandler (/Users/kanej/repos/nomic/hardhat/v-next/hardhat-ledger/src/internal/handler.ts:83:46)
    at <anonymous> (/Users/kanej/repos/nomic/hardhat/v-next/hardhat-ledger/src/internal/hook-handlers/network.ts:53:34)
    at AsyncMutex.exclusiveRun (/Users/kanej/repos/nomic/hardhat/v-next/hardhat/src/internal/core/async-mutex.ts:24:20)
    at async Array.onRequest (/Users/kanej/repos/nomic/hardhat/v-next/hardhat-ledger/src/internal/hook-handlers/network.ts:48:29)
    at async next (/Users/kanej/repos/nomic/hardhat/v-next/hardhat/src/internal/core/hook-manager.ts:124:13)

If you think this is a bug in Hardhat, please report it here: https://hardhat.org/report-bug

The issue is that the Ledger handler assumes that networkConnection.networkConfig.ledgerAccounts is populated:

// v-next/hardhat-ledger/src/internal/hook-handlers/network.ts line 48
handlerPerConnection = new LedgerHandler(
  networkConnection.provider,
  {
    accounts: networkConnection.networkConfig.ledgerAccounts,
  },
  context.interruptions.displayMessage.bind(context.interruptions),
);

The version of networkConfig associated with the connection is a clone, but the bug is that the ledgerAccounts are not being copied across.

This PR updates the config creation during network connection creation to merge the user provided network config (extended by plugins) and the overrides.

Test locally

cd v-next/example-project
pnpm build
pnpm hardhat node

Copy link

changeset-bot bot commented Aug 1, 2025

⚠️ No Changeset found

Latest commit: bb1f279

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Member

@schaable schaable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should merge these recursively, but this seems good enough for now.

@kanej
Copy link
Member Author

kanej commented Sep 3, 2025

I have spoken with Pato on this to check the logic.
We could merge this PR and it would resolve the hardhat-ledger problem with npx hardhat node.
However, we should fix the underlying issue, which is that we are not extending config here in the same way we do within the main config resolution.
We need to look at pull across some of that machinery to network config resolution. Right now that resolution does not have extension points.
This PR is not merge-able until then.

@kanej kanej force-pushed the network-connection-config-extension-copying branch from 2819642 to 94c0577 Compare September 8, 2025 10:07
@kanej kanej changed the base branch from v3-hh-ledger to main September 8, 2025 10:07
Allow network config to have unspecified properties to support plugins
extending the network config.

We disable a test that specifically checks whether we error for users
combining both HTTP and EDR network config properties.

It is not obvious how we keep this test and allow network config
extensions.
This is to support type extensions
This is a preparatory move before we rework it to support plugin
additions.
@kanej kanej force-pushed the network-connection-config-extension-copying branch from 94c0577 to bb1f279 Compare September 12, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

3 participants