add compatibility with hardhat node#1535
Merged
ZePedroResende merged 6 commits intomainfrom Jan 29, 2026
Merged
Conversation
naps62
approved these changes
Jan 29, 2026
Contributor
There was a problem hiding this comment.
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_metadatafor devnet detection/fork info andhardhat_impersonateAccountfor account impersonation, while keeping Anvil compatibility. - Introduce the
ethui-sync-devnetcrate (renamed fromethui-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
SendTransactionto impersonate accounts via Hardhat/Anvil directly using wallet-derived addresses, and adjust workspace wiring (Cargo.toml,Cargo.lock, crate references) fromethui-sync-anviltoethui-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.
1bd322c to
9c2fc20
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.