Skip to content

Use code 3 for JSON-RPC responses where there has been a revert#8104

Merged
ChristopherDedominici merged 22 commits intomainfrom
error-code-3
Apr 14, 2026
Merged

Use code 3 for JSON-RPC responses where there has been a revert#8104
ChristopherDedominici merged 22 commits intomainfrom
error-code-3

Conversation

@ChristopherDedominici
Copy link
Copy Markdown
Contributor

Fixes: #8043

Copilot AI review requested due to automatic review settings April 2, 2026 12:36
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 2, 2026

🦋 Changeset detected

Latest commit: 92ba0a7

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

This PR includes changesets to release 7 packages
Name Type
@nomicfoundation/hardhat-ethers Patch
@nomicfoundation/hardhat-ignition-viem Patch
@nomicfoundation/hardhat-ignition Patch
@nomicfoundation/hardhat-toolbox-viem Patch
@nomicfoundation/hardhat-viem-assertions Patch
@nomicfoundation/hardhat-viem Patch
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

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 Hardhat’s JSON-RPC error handling to align revert responses with the de facto geth/anvil convention (error code: 3 and raw hex revert data), improving compatibility with tooling that expects this shape (per #8043).

Changes:

  • Treat errors with numeric code === 3 as revert errors and emit geth/anvil-style JSON-RPC error responses (raw hex data).
  • Add code = 3 (and name) to SolidityError so stack-trace-based reverts propagate with the expected JSON-RPC error code.
  • Update node JSON-RPC handler tests to validate the new response shape for code-3 errors.

Reviewed changes

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

File Description
packages/hardhat/test/internal/builtin-plugins/node/json-rpc/handler.ts Adjusts tests to assert geth/anvil-style revert error formatting for code-3 errors.
packages/hardhat/src/internal/builtin-plugins/node/json-rpc/handler.ts Updates _handleError to avoid wrapping code-3 errors and to serialize revert data as a raw hex string.
packages/hardhat/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.ts Adds SolidityError.CODE/code (3) and sets name to ensure revert errors carry the expected code.

Copilot AI review requested due to automatic review settings April 7, 2026 10:15
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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Comment thread packages/hardhat/src/internal/builtin-plugins/node/json-rpc/handler.ts Outdated
Copilot AI review requested due to automatic review settings April 8, 2026 14:36
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 8, 2026

hardhat

Total size of the bundle: 246M
Total number of dependencies (including transitive): 48

List of dependencies (sorted by size)
238M	total
37M	@nomicfoundation/edr-linux-x64-musl
37M	@nomicfoundation/edr-linux-x64-gnu
34M	@nomicfoundation/edr-linux-arm64-musl
34M	@nomicfoundation/edr-linux-arm64-gnu
25M	@nomicfoundation/edr-darwin-x64
24M	@nomicfoundation/edr-win32-x64-msvc
21M	@nomicfoundation/edr-darwin-arm64
7.3M	@sentry/core
5.2M	zod
2.7M	micro-eth-signer
1.9M	@noble/curves
1.7M	undici
1.2M	@noble/hashes
1.1M	@nomicfoundation/hardhat-utils
884K	@nomicfoundation/hardhat-vendored
864K	@streamparser/json
624K	micro-packed
592K	tsx
588K	@nomicfoundation/hardhat-errors
492K	@scure/bip39
476K	@nomicfoundation/edr
408K	json-stream-stringify
368K	ethereum-cryptography
344K	fast-equals
332K	@streamparser/json-node
320K	enquirer
320K	@nomicfoundation/hardhat-zod-utils
288K	semver
200K	ws
180K	chokidar
176K	get-tsconfig
168K	esbuild
168K	@scure/base
136K	adm-zip
96K	@scure/bip32
92K	chalk
72K	@nomicfoundation/solidity-analyzer
68K	debug
60K	readdirp
56K	rfdc
48K	ansi-colors
44K	resolve.exports
40K	resolve-pkg-maps
36K	p-map
24K	strip-ansi
24K	env-paths
24K	ansi-regex
20K	ms

@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 8, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedviem@​2.43.5 ⏵ 2.47.698 +1100100 +197100

View full report

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

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

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Comment thread packages/example-project/test/node/test-revert.ts Outdated
Comment thread packages/example-project/test/node/test-revert.ts Outdated
Comment thread packages/example-project/test/node/test-revert.ts Outdated
Comment thread packages/example-project/test/node/test-revert.ts Outdated
Comment thread packages/example-project/test/node/test-revert.ts Outdated
Comment thread packages/hardhat/test/internal/builtin-plugins/node/json-rpc/handler.ts Outdated
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

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

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Comment thread packages/hardhat-viem/test/revert-error-chain.ts
Comment thread packages/hardhat-viem/test/revert-error-chain.ts
@ChristopherDedominici ChristopherDedominici marked this pull request as ready for review April 10, 2026 12:42
Copilot AI review requested due to automatic review settings April 10, 2026 12:42
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

Copilot reviewed 18 out of 19 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
import { ensureError } from "@nomicfoundation/hardhat-utils/error";
import { isPrefixedHexString } from "@nomicfoundation/hardhat-utils/hex";
import {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't get why this needs to be changed. I would have assumed that it was still working as expected.

If I revert the changes to this package, except for the package.json, the tests still pass.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done here: b5e2f69

@@ -0,0 +1,176 @@
import type { HardhatViemHelpers } from "@nomicfoundation/hardhat-viem/types";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this tests should be present in hardhat-viem, not this package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done here: 5cb67ab

@github-project-automation github-project-automation Bot moved this from In Progress to In Review in Hardhat Apr 10, 2026
Copilot AI review requested due to automatic review settings April 13, 2026 12:46
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

Copilot reviewed 16 out of 17 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Comment thread packages/hardhat-viem/test/revert-error-chain.ts Outdated
Copy link
Copy Markdown
Member

@alcuadrado alcuadrado left a comment

Choose a reason for hiding this comment

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

left a tiny comment but LGTM

Co-authored-by: Patricio Palladino <email@patriciopalladino.com>
Copilot AI review requested due to automatic review settings April 14, 2026 09:36
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

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

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Comment on lines +110 to +123
server = await hre.network.createServer();
({ address, port } = await server.listen());
});

after(async () => {
await server.close();
});

beforeEach(async () => {
({ viem } = await hre.network.connect({
network: "localhost",
override: {
url: `http://${address}:${port}`,
},
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

In the HTTP suite, the test uses the address returned by server.listen() to build the client URL. When the JSON-RPC server is bound to 0.0.0.0/:: (common in Docker/CI), that address is not always a reliable connect target for HTTP clients and can make this test flaky. Prefer binding the server explicitly to 127.0.0.1 (e.g. via hre.network.createServer("default", "127.0.0.1")) and using 127.0.0.1 in the override URL, while still keeping port from listen().

Copilot uses AI. Check for mistakes.
@ChristopherDedominici ChristopherDedominici added this pull request to the merge queue Apr 14, 2026
Merged via the queue into main with commit 1039dbc Apr 14, 2026
300 checks passed
@ChristopherDedominici ChristopherDedominici deleted the error-code-3 branch April 14, 2026 10:08
@github-project-automation github-project-automation Bot moved this from In Review to Done in Hardhat Apr 14, 2026
@github-actions github-actions Bot mentioned this pull request Apr 14, 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

Status: Done

Development

Successfully merging this pull request may close these issues.

Use code 3 for JSON-RPC responses where there has been a revert

4 participants