Skip to content

feat(tx): TX Analyser — call tree, state changes, and contract enrichment#281

Open
AugustoL wants to merge 13 commits intodevfrom
feat/tx-analyser
Open

feat(tx): TX Analyser — call tree, state changes, and contract enrichment#281
AugustoL wants to merge 13 commits intodevfrom
feat/tx-analyser

Conversation

@AugustoL
Copy link
Collaborator

@AugustoL AugustoL commented Mar 6, 2026

Description

Adds a TX Analyser panel to the transaction details page (visible in Super User mode). Inspired by tools like Tenderly, it provides a deep-dive into transaction execution without leaving OpenScan.

Related Issue

Closes #274

Type of Change

  • New feature

Changes Made

Adapters

  • Added getAnalyserCallTrace and getAnalyserPrestateTrace abstract methods to NetworkAdapter
  • Implemented in all network adapters (EVM, Arbitrum, Optimism, Base, BNB, Polygon) using debug_traceTransaction with callTracer / prestateTracer
  • Arbitrum tries Geth callTracer first, falls back to arbtrace_transaction (Parity flat format)

Utilities

  • callTreeUtils.ts — normalize Geth and Parity/arbtrace traces to a unified CallNode tree; helpers: countCalls, countReverts, countByType, collectAddresses, hexToGas
  • contractLookup.ts — fetch contract name + ABI from Sourcify (Etherscan V2 fallback when API key is configured); session-level cache keyed by chainId:address

Hooks

  • useCallTreeEnrichment — enriches all addresses in a call tree in parallel; aborts on tree/network change

UI (TxAnalyser.tsx)

  • Call Tree tab: expandable/collapsible node tree, call type badges (color-coded), from → to with contract names, decoded function calls (transfer(0x1234…, 100)), ETH value, gas used, error badges
  • State Changes tab: per-address balance/nonce/storage/code diffs with contract names
  • Summary bar: total gas, call count, per-type breakdown (e.g. 3× STATICCALL), revert count, enrichment loading indicator

Integration

  • TransactionDisplay.tsx — collapsible "TX Analyser ▼" section, shown only when isSuperUser is enabled
  • Translations: all 5 locales (en, es, ja, pt-BR, zh) with analyser.* keys
  • CSS: full styling for analyser tabs, call tree nodes, state change blocks

Screenshots (if applicable)

To be added — test with any mainnet transaction on a trace-enabled RPC (dRPC, Tenderly).

Checklist

  • I have run npm run format:fix and npm run lint:fix
  • I have run npm run typecheck with no errors
  • I have run tests with npm run test:run
  • I have tested my changes locally
  • I have updated documentation if needed
  • My code follows the project's architecture patterns

Additional Notes

  • Trace methods work on any RPC that supports debug_traceTransaction (dRPC free tier, Tenderly, Alchemy, Ankr with key). The UI shows a clear "not supported" message with provider suggestions when the RPC doesn't support traces.
  • Contract enrichment (Sourcify) works without any API key. Etherscan fallback activates only when settings.apiKeys.etherscan is set (opt-in).
  • etherscan field added to ApiKeys type in anticipation of PR feat(address): proxy contract detection + Etherscan verification source #279 (Etherscan as verification source).

… enrichment

Adds a TX Analyser panel (super user mode) to the transaction details page.

- Adds getAnalyserCallTrace / getAnalyserPrestateTrace to all network adapters (EVM, Arbitrum, Optimism, Base, BNB, Polygon) using debug_traceTransaction with callTracer / prestateTracer; Arbitrum falls back to arbtrace_transaction
- New CallNode / PrestateTrace types in NetworkAdapter
- New callTreeUtils: normalizeGethCallTrace, normalizeParityCallTrace, countCalls, countReverts, countByType, collectAddresses, hexToGas
- New contractLookup utility: fetches contract name + ABI from Sourcify (Etherscan fallback when key configured); session-level cache
- New useCallTreeEnrichment hook: enriches all call tree addresses in parallel, aborts on tree change
- TxAnalyser component: Call Tree tab with expandable nodes, decoded function calls, contract names, per-type summary; State Changes tab with balance/nonce/storage/code diffs and contract names
- Collapsible TX Analyser section in TransactionDisplay (super users only)
- Translations for all 5 locales (en, es, ja, pt-BR, zh)
- All CSS styles for analyser, call tree, and state change components
@github-actions
Copy link

github-actions bot commented Mar 6, 2026

🚀 Preview: https://pr-281--openscan.netlify.app
📝 Commit: 0d7154d610de2e3cdf9bae448a7c6df13f13c1ac

AugustoL added 12 commits March 12, 2026 16:55
Adds a Gas Profiler tab to the TX Analyser that shows how gas is
spent across all operations in a transaction. Flattens the call tree
into a sorted table with columns: type, contract, function, gas used
(with percentage bar). Reuses existing call tree data — no additional
RPC calls needed.

Translations added for all 5 locales (en, es, ja, pt-BR, zh).
…it for contract enrichment

Replace the table-based Gas Profiler with a Tenderly-style icicle/flame chart
with click-to-zoom and breakdown panel. All analyser tabs now wait for contract
ABI enrichment to complete before rendering, ensuring decoded function names
are displayed instead of raw selectors.
In super user mode, event logs are now displayed inside the TX Analyser
as a dedicated Events tab instead of a separate collapsible section.
The Events tab leverages enriched contract ABIs from the call tree
enrichment to decode events from all addresses, not just the tx recipient.
Non-super-user mode retains the original collapsible event logs section.
In super user mode, raw and decoded input data are now displayed inside
the TX Analyser as an Input Data tab. The tab also tries enriched ABIs
from call tree enrichment as a fallback for decoding. Non-super-user
mode retains the original input data rows in the transaction details.
Remove the collapsible toggle button — the TX Analyser section is now
always visible when super user mode is active.
Fix race condition where call tree tabs rendered with empty contracts
for one frame before the enrichment useEffect had a chance to run.
Track a pendingEnrichment state to bridge the gap between when the
call tree arrives and when the async enrichment effect fires.
Replace pendingEnrichment workaround with a simpler done-flag approach.
enrichmentLoading is now true from the moment a call tree exists until
all contract info has been fetched, eliminating any render gap.
Sourcify V2 API does not have a top-level 'name' field — the contract
name is nested under compilation.name. Changed the request from
?fields=abi,name (which returned a 400 error) to ?fields=abi,compilation
and extracted the name from compilation.name.
…Data tabs

The TX Analyser is now always visible on transaction pages. Base users
see Events and Input Data tabs. Super user mode unlocks Call Tree, Gas
Profiler, and State Changes tabs. Trace fetching is skipped in base
mode. Removed duplicate event logs and input data sections from
TransactionDisplay since TxAnalyser now handles them for all users.
Base user tabs (Events, Input Data) use --text-primary when active.
Super user tabs (Call Tree, Gas Profiler, State Changes) use
--color-accent to visually signal the user is viewing advanced data.
@AugustoL AugustoL requested a review from josealoha666 March 12, 2026 21:02
@AugustoL AugustoL self-assigned this Mar 12, 2026
@AugustoL AugustoL marked this pull request as ready for review March 12, 2026 21:03
@MatiasOS
Copy link
Member

This looks really really good!!

  • This headers should use full address. Is not necessary to shorttened
image
  • It will better if events and state changes headers are collapsed by default?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants