Skip to content

fixes for createServer#8060

Merged
kanej merged 3 commits intomainfrom
fix/create-server-type
Mar 16, 2026
Merged

fixes for createServer#8060
kanej merged 3 commits intomainfrom
fix/create-server-type

Conversation

@kanej
Copy link
Copy Markdown
Member

@kanej kanej commented Mar 13, 2026

This includes two small changes but touches the type of network.createServer.

  1. It alters the network parameters type to allow chain types other than generic
  2. It throws if createServer is used against a network config that is not edr-simulated (copying the pattern in npx hardhat node)

The changes are commit at a time.

createServer Type

The current type would show an error for the following code:

import { network } from "hardhat";

const server = await network.createServer(
  {
    network: "edrOp",
    chainType: "op", // <------ error: expected "generic"
  },
  "0.0.0.0",
  8545,
);

This PR accepts op without a type error. An alternative is to say that chainType makes no sense for the createServer method and Omit<> the property from the createServer interface.

Copilot AI review requested due to automatic review settings March 13, 2026 10:53
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 13, 2026

🦋 Changeset detected

Latest commit: 0a7deea

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

This PR includes changesets to release 2 packages
Name Type
hardhat Patch
@nomicfoundation/hardhat-errors 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 added no docs needed This PR doesn't require links to documentation no peer bump needed labels Mar 13, 2026
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

Updates network.createServer to better support non-generic chain types while enforcing that servers can only be created from edr-simulated network configs (mirroring hardhat node behavior).

Changes:

  • Generalize NetworkManager.createServer typing to accept NetworkConnectionParams<ChainTypeT> so chainType: "op" (and other chain types) type-checks.
  • Add a runtime guard that throws a dedicated Hardhat error when createServer targets a non-edr-simulated network (e.g. http/localhost).
  • Add tests + a new example script demonstrating spinning up a server and sending a tx.

Reviewed changes

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

Show a summary per file
File Description
v-next/hardhat/test/internal/builtin-plugins/network-manager/network-manager.ts Adds coverage for the new createServer restriction and validates server usage end-to-end.
v-next/hardhat/src/types/network.ts Adjusts the public NetworkManager.createServer type signature to accept non-default chainTypes.
v-next/hardhat/src/internal/builtin-plugins/network-manager/network-manager.ts Enforces createServer is only usable for edr-simulated networks via a new guard + dedicated error.
v-next/hardhat-errors/src/descriptors.ts Introduces CREATE_SERVER_UNSUPPORTED_NETWORK_TYPE error descriptor for the new runtime validation.
v-next/example-project/scripts/create-server.ts Adds an example script demonstrating network.createServer with chainType: "op".

You can also share your feedback on Copilot code review. Take the survey.

Comment thread v-next/example-project/scripts/create-server.ts Outdated
Comment thread v-next/example-project/scripts/create-server.ts Outdated
@kanej kanej force-pushed the fix/create-server-type branch from 29f4e9b to abc60d4 Compare March 13, 2026 11:00
Comment on lines +113 to +116
public async createServer<
ChainTypeT extends ChainType | string = DefaultChainType,
>(
networkOrParams: NetworkConnectionParams<ChainTypeT> | string = "default",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the key type change. It is backwards compatible.

The alternative is to remove chainType as it does not make sense for createServer (no connection instance is returned).

@kanej kanej force-pushed the fix/create-server-type branch from abc60d4 to 03f4972 Compare March 13, 2026 11:07
Copilot AI review requested due to automatic review settings March 13, 2026 11:07
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 PR updates network.createServer to (1) accept non-"generic" chainTypes in its parameter typing, and (2) fail fast at runtime when called against an http network configuration (matching the behavior pattern used by hardhat node).

Changes:

  • Updated network.createServer TypeScript signature to support typed non-generic chainType values.
  • Added a runtime guard that throws a dedicated Hardhat error when createServer targets a non-edr-simulated network config, plus added corresponding tests.
  • Added a new error descriptor and an example script demonstrating createServer.

Reviewed changes

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

Show a summary per file
File Description
v-next/hardhat/test/internal/builtin-plugins/network-manager/network-manager.ts Adds coverage for rejecting createServer on http networks and validates server connectivity.
v-next/hardhat/src/types/network.ts Makes createServer generic over ChainTypeT to allow non-"generic" chain types in params.
v-next/hardhat/src/internal/builtin-plugins/network-manager/network-manager.ts Adds a guard that throws when createServer is invoked for non-edr-simulated network configs.
v-next/hardhat-errors/src/descriptors.ts Introduces CREATE_SERVER_UNSUPPORTED_NETWORK_TYPE error descriptor.
v-next/example-project/scripts/create-server.ts Adds an example using network.createServer and interacting with the resulting JSON-RPC server.
.changeset/petite-teams-slide.md Changeset for the new runtime guard / error.
.changeset/cyan-dogs-ask.md Changeset for the createServer typing update.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread v-next/example-project/scripts/create-server.ts Outdated
Comment thread v-next/example-project/scripts/create-server.ts Outdated
kanej added 2 commits March 13, 2026 11:14
The type was stopping `createServer` from passing the `op` chainType as
part of the network parameters. The type has been enhanced to
generically capture the ChainType.
Match the behaviour of `npx hardhat node` and throw if a network config
with a type other than `edr-simulated` is used.
@kanej kanej force-pushed the fix/create-server-type branch from 03f4972 to 0e8abcf Compare March 13, 2026 11:14
@kanej kanej marked this pull request as ready for review March 13, 2026 11:29
@kanej kanej requested review from alcuadrado and Copilot March 13, 2026 11:29
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

Updates network.createServer to better support different chain types at the type level and to fail fast when invoked against unsupported (HTTP) network configurations.

Changes:

  • Generalized NetworkManager.createServer typing to accept non-generic chainType values via generics.
  • Added a runtime guard that throws a dedicated Hardhat error when createServer targets a non-edr-simulated network.
  • Expanded createServer tests and added new error descriptor + changesets.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
v-next/hardhat/test/internal/builtin-plugins/network-manager/network-manager.ts Adds regression tests for createServer rejecting HTTP networks and validates the server can be used via an HTTP client.
v-next/hardhat/src/types/network.ts Updates the public NetworkManager.createServer signature to be generic over ChainType.
v-next/hardhat/src/internal/builtin-plugins/network-manager/network-manager.ts Implements the runtime guard and updates createServer signature accordingly.
v-next/hardhat-errors/src/descriptors.ts Introduces CREATE_SERVER_UNSUPPORTED_NETWORK_TYPE error descriptor.
.changeset/petite-teams-slide.md Changeset for the new createServer guard behavior.
.changeset/cyan-dogs-ask.md Changeset for the createServer type signature update.

You can also share your feedback on Copilot code review. Take the survey.

Use the same pattern as `connect` so that the passed default network is
used properly.
@kanej kanej added this pull request to the merge queue Mar 16, 2026
Merged via the queue into main with commit c492e06 Mar 16, 2026
249 checks passed
@kanej kanej deleted the fix/create-server-type branch March 16, 2026 16:21
@github-actions github-actions Bot mentioned this pull request Mar 16, 2026
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.

3 participants