Skip to content

Comments

add compatibility with hardhat node#1535

Merged
ZePedroResende merged 6 commits intomainfrom
zpr/hardhat-node
Jan 29, 2026
Merged

add compatibility with hardhat node#1535
ZePedroResende merged 6 commits intomainfrom
zpr/hardhat-node

Conversation

@ZePedroResende
Copy link
Contributor

@ZePedroResende ZePedroResende commented Jan 29, 2026

  • Replace Anvil-specific RPC helpers with Hardhat-compatible calls: hardhat_metadata for devnet detection/fork info and hardhat_impersonateAccount for account impersonation, while keeping Anvil compatibility.
  • Introduce the ethui-sync-devnet crate (renamed from ethui-sync-anvil)

@ZePedroResende ZePedroResende added the A-enhancement work towards a new feature label Jan 29, 2026
@ZePedroResende ZePedroResende marked this pull request as ready for review January 29, 2026 15:16
Copy link
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 generalizes the existing Anvil-only devnet support to work with Hardhat (and similar devnets) by switching to Hardhat-compatible JSON-RPC methods and renaming the sync crate to ethui-sync-devnet. It wires the new devnet sync crate into the main sync pipeline, adds a dedicated devnet tracker/worker stack (HTTP and WebSocket), and updates transaction sending to use Hardhat’s impersonation mechanics.

Changes:

  • Replace Anvil-specific RPC helpers with Hardhat-compatible calls: hardhat_metadata for devnet detection/fork info and hardhat_impersonateAccount for account impersonation, while keeping Anvil compatibility.
  • Introduce the ethui-sync-devnet crate (renamed from ethui-sync-anvil) containing devnet utilities, tracers, consumer, HTTP/WS providers, worker orchestration, and tests; hook it into the global sync initialization and native-balance commands.
  • Update SendTransaction to impersonate accounts via Hardhat/Anvil directly using wallet-derived addresses, and adjust workspace wiring (Cargo.toml, Cargo.lock, crate references) from ethui-sync-anvil to ethui-sync-devnet.

Reviewed changes

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

Show a summary per file
File Description
crates/types/src/network/mod.rs Switch devnet detection and fork metadata retrieval from anvil_* helpers to hardhat_metadata, and import Metadata/ForkedNetwork to keep get_forked_network working with both Anvil and Hardhat; one unused AnvilApi import remains.
crates/sync/src/lib.rs Change sync initialization to call ethui_sync_devnet::init() so the devnet-specific tracker is started instead of the old Anvil-specific one.
crates/sync/src/commands.rs Route dev-network native balance reads through ethui_sync_devnet::get_native_balance when network.is_dev().await is true.
crates/sync/devnet/src/utils.rs Provide devnet helpers: a thin get_native_balance over Alloy and an async fetch_erc20_metadata used by the devnet consumer.
crates/sync/devnet/src/tracker/ws.rs Implement a WebSocket-based AnvilWs provider that connects via ws_url, subscribes to live block headers, and exposes historical backfill; current implementations box and pin streams more than necessary.
crates/sync/devnet/src/tracker/worker.rs Add the core devnet Worker that waits for node availability with exponential backoff/jitter, backfills from fork point, then streams live blocks with checkpoint validation; includes an AnvilProviderType enum to choose HTTP vs WS and extensive unit tests of worker lifecycle and error paths.
crates/sync/devnet/src/tracker/utils.rs Factor out try_get_sync_info to query latest block and fork block number via hardhat_metadata, and provide a deterministic jitter generator for retry backoff.
crates/sync/devnet/src/tracker/provider.rs Define the AnvilProvider async trait abstraction over HTTP/WS providers, returning boxed header streams for subscription and backfill.
crates/sync/devnet/src/tracker/mod.rs Manage per-network worker lifecycles via a global Lazy map, exposing watch/unwatch primitives and tests verifying correct worker creation, deduplication, and shutdown behavior.
crates/sync/devnet/src/tracker/http.rs Implement AnvilHttp using HTTP polling (watch_blocks) and range-based historical fetch, returning boxed header streams; currently uses an extra layer of boxing/pinning that could be simplified.
crates/sync/devnet/src/tracker/consumer.rs Define a generic Consumer trait and an EthuiConsumer that pulls traces/logs per block, expands them into events, persists them, backfills missing ERC20 metadata, and emits UI notifications when caught up.
crates/sync/devnet/src/tests/utils.rs Provide a simple TestConsumer used in tracker/worker tests to log processed messages without touching the database.
crates/sync/devnet/src/tests/mod.rs Wire up the devnet tracker test modules (anvil_tests and test utilities).
crates/sync/devnet/src/tests/anvil_tests.rs Add higher-level tests around HTTP/WS workers, wait behavior against unreachable nodes, block subscription interfaces, and combined historical/live streaming behavior, all designed to run without a real Anvil instance.
crates/sync/devnet/src/lib.rs Define the ethui-sync-devnet crate structure, exposing init and get_native_balance along with the tracker module.
crates/sync/devnet/src/init.rs Start a background task subscribing to internal messages and (un)watch networks whose is_dev() flag is true, so only devnets get a devnet worker.
crates/sync/devnet/src/expanders.rs Implement trace/log expansion for devnet: derive Tx and ContractDeployed events from parity traces and decode ERC20 Transfer logs into ERC20Transfer events.
crates/sync/devnet/src/bin/devnet-sync-test.rs Update the test binary to reference ethui_sync_devnet::tracker while preserving its Anvil-oriented CLI interface for manually exercising the worker.
crates/sync/devnet/Cargo.toml Rename the crate to ethui-sync-devnet, rename the test binary, and declare dependencies (Alloy, tracing, clap, etc.) appropriate for the new devnet sync implementation.
crates/sync/Cargo.toml Swap the dependency from ethui-sync-anvil to ethui-sync-devnet in the main sync crate.
crates/rpc/src/methods/send_transaction.rs Update transaction sending on devnets to compute an address from the resolved wallet, call hardhat_impersonateAccount via Alloy’s client, and drop the ext::AnvilApi usage, while non-devnet flows still attach a signer wallet.
Cargo.toml Replace the workspace-level ethui-sync-anvil member with ethui-sync-devnet so the new devnet crate is part of the workspace.
Cargo.lock Regenerate lockfile entries to reflect the rename from ethui-sync-anvil to ethui-sync-devnet and updated dependency wiring.

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

@ZePedroResende ZePedroResende enabled auto-merge (rebase) January 29, 2026 15:57
@ZePedroResende ZePedroResende merged commit fee4545 into main Jan 29, 2026
7 checks passed
@ZePedroResende ZePedroResende deleted the zpr/hardhat-node branch January 29, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-enhancement work towards a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants