Skip to content

Allow overriding the type of the default network#7805

Merged
alcuadrado merged 6 commits intomainfrom
fix-default-network
Feb 23, 2026
Merged

Allow overriding the type of the default network#7805
alcuadrado merged 6 commits intomainfrom
fix-default-network

Conversation

@fvictorio
Copy link
Copy Markdown
Contributor

This fixes #7795, but I'm not fully convinced about the change.

The problem is that we are always setting the type of default network to be a simulated network, and we also set some other default values. This makes sense, but it does seem to assume that the network is not of type http. My concern is that a user's settings could interact in the wrong way with those default values.

On the other hand, without this change there's no way to have an http network as the default network, something that was possible in HH2.

One alternative here is to re-introduce the defaultNetwork config, and default it to "default" (yes).

Another alternative is to only use those default values if the user doesn't change the type, but that starts feeling a bit too complex.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Dec 17, 2025

🦋 Changeset detected

Latest commit: da3b1ae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hardhat Patch

Not sure what this means? Click here to learn what changesets are.

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

@kanej kanej requested a review from alcuadrado December 18, 2025 15:13
@kanej kanej removed the request for review from alcuadrado January 14, 2026 15:53
@kanej kanej marked this pull request as ready for review January 14, 2026 15:53
@kanej kanej added the no docs needed This PR doesn't require links to documentation label Jan 14, 2026
@kanej
Copy link
Copy Markdown
Member

kanej commented Jan 14, 2026

We should double check running tests against a npx hardhat node instance, and add a changeset.
But in principle we are happy with this approach to let users set default to an http network.

Copy link
Copy Markdown
Contributor

@michalbrabec michalbrabec left a comment

Choose a reason for hiding this comment

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

Overriding the default network creates the need to setup a new network for npx hardhat node and then used it with the --network parameter.
#7795 (comment)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes issue #7795 by allowing users to override the type of the default and localhost network configurations. Previously, these networks had their types forced to specific values (default was always edr-simulated and localhost was always http), preventing users from configuring the default network as an HTTP network pointing to an external node.

Changes:

  • Modified network configuration extension logic to respect user-specified network types
  • Updated tests to verify that network types can now be overridden
  • Added comprehensive test cases for overriding both default and localhost network types

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
v-next/hardhat/src/internal/builtin-plugins/network-manager/hook-handlers/config.ts Refactored extendUserConfig to conditionally apply defaults based on network type, allowing users to override the type of default and localhost networks
v-next/hardhat/test/internal/builtin-plugins/network-manager/hook-handlers/config.ts Updated test descriptions and added new test cases to verify that network type overrides work correctly for both localhost and default networks
.changeset/four-lies-flash.md Added changeset documenting the patch-level change

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alcuadrado alcuadrado mentioned this pull request Feb 22, 2026
@alcuadrado
Copy link
Copy Markdown
Member

I went for an option where we only set the defaults if the network is undefined, it has no type, or the type matches the expected one. Otherwise I just forward whatever the user provided.

I also implemented the same logic for localhost, so that no network in this PR has any unexpected behavior.

Copy link
Copy Markdown
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.

LGTM

@alcuadrado alcuadrado added this pull request to the merge queue Feb 23, 2026
Merged via the queue into main with commit 9eaaf20 Feb 23, 2026
203 checks passed
@alcuadrado alcuadrado deleted the fix-default-network branch February 23, 2026 15:46
@github-actions github-actions Bot mentioned this pull request Feb 23, 2026
@kanej
Copy link
Copy Markdown
Member

kanej commented Feb 25, 2026

This has been released as part of hardhat@3.1.10: https://github.com/NomicFoundation/hardhat/releases/tag/hardhat%403.1.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no docs needed This PR doesn't require links to documentation no peer bump needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configuration for default network is ignored

6 participants