Skip to content

feat(cli): add tx simulate and trace subcommands#667

Draft
ByteYue wants to merge 2 commits into
mainfrom
feat/cli-tx-simulate-trace
Draft

feat(cli): add tx simulate and trace subcommands#667
ByteYue wants to merge 2 commits into
mainfrom
feat/cli-tx-simulate-trace

Conversation

@ByteYue
Copy link
Copy Markdown
Contributor

@ByteYue ByteYue commented Apr 19, 2026

Summary

Three new read-only helpers that wrap reth's debug RPC for the common "what would happen / what happened" developer questions:

  • tx simulate --from --to --data [--value] [--block] — runs eth_call + eth_estimateGas and pretty-prints the outcome. Reverts are decoded for the two standard ABI signatures (Error(string), Panic(uint256)); unknown selectors fall back to raw hex. Exit code is non-zero on revert so simulate can gate scripts.

  • tx trace <hash> [--tracer call|prestate|4byte|opcode|noop] — wraps debug_traceTransaction. The call tracer is rendered as an indented tree (• CALL 0xfrom → 0xto value=N gas=used/limit); everything else prints pretty JSON.

  • tx trace-call --from --to --data [--value] [--block] [--tracer ...] — wraps debug_traceCall for hypothetical calls, using the same tracers and rendering.

--output json on any of the three produces machine-readable output for scripting.

Design notes

  • No node-side changes — everything layers on reth methods already exposed (eth_call, eth_estimateGas, debug_traceTransaction, debug_traceCall).
  • Revert decoding lives in tx/common.rs with unit tests for the standard selectors, the empty-data case, and the hex-fallback case. Custom-error ABI support is deferred.
  • Relationship with foundry's cast: cast covers vanilla EVM flows; this PR focuses on gravity-specific simulation flow + making revert output first-class. No overlap we're duplicating.

Test plan

  • Unit tests (revert decoding Error/Panic/empty/unknown, hex parsing) — 6 tests pass
  • tx simulate successful EOA transfer against localnet → prints success / return / gas
  • tx simulate with insufficient balance → reverted, exit 1
  • tx trace <real tx hash> (callTracer) → tree output with from/to/value/gas
  • tx trace --tracer prestate → pretty JSON passthrough
  • tx trace-call → successfully traces hypothetical call
  • --output json produces structured output for simulate and trace
  • Invalid tx hash → clear error, exit 1
  • Missing --rpc-url → clear error with init hint

ByteYue added 2 commits April 19, 2026 17:32
Three new read-only helpers that wrap reth's debug RPC for the common
\"what would happen / what happened\" developer questions:

  - `tx simulate --from --to --data [--value] [--block]` runs eth_call
    + eth_estimateGas and pretty-prints the outcome. Reverts are decoded
    for the two standard ABI signatures (`Error(string)`, `Panic(uint256)`);
    unknown selectors fall back to raw hex. Exit code is non-zero on
    revert so simulate can gate scripts.
  - `tx trace <hash> [--tracer call|prestate|4byte|opcode|noop]` wraps
    `debug_traceTransaction`. The `call` tracer is rendered as an
    indented tree; everything else prints pretty JSON.
  - `tx trace-call --from --to --data [--value] [--block] [--tracer ...]`
    wraps `debug_traceCall` for hypothetical calls, using the same
    tracers and rendering.

Revert decoding logic lives in tx/common.rs with unit tests for the
standard selectors, the empty-data case, and the hex-fallback case.

No node-side changes — purely a CLI wrapper over methods reth already
exposes.
@ByteYue ByteYue marked this pull request as draft April 22, 2026 02:10
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.

1 participant