@valve-tech/trace-sdk
v0.4.0
Published
Standalone EVM trace loading, traversal, and rendering toolkit. No platform dependencies.
Maintainers
Readme
@valve-tech/trace-sdk
Standalone EVM trace loading, traversal, and rendering toolkit. No platform dependencies — works against any JSON-RPC node that supports debug_traceTransaction / debug_traceCall.
Originally extracted from the PulseChain Dev Platform debugger. Works for any EVM chain, not just PulseChain.
Install
npm install @valve-tech/trace-sdk viem
# React components are optional — only install if you'll render them
npm install reactPeer dependencies:
| Package | Required | Why |
|---------|----------|-----|
| viem | yes | RPC calls in loadTraceFromHash, address utilities |
| react (>=18) | optional | Only for CallTree, GasFlamegraph, OpcodeViewer components |
Quickstart
// TODO: your quickstart snippet hereSubpath exports
Tree-shake friendly — import only what you need:
import { parseCallTrace } from "@valve-tech/trace-sdk/loaders";
import { walkCallTree, buildGasProfile } from "@valve-tech/trace-sdk/traversal";
import { parseTokenDeltas, parsePrestateDiff } from "@valve-tech/trace-sdk/parsers";
import { analyzeRisks } from "@valve-tech/trace-sdk/risks";
import { CallTree, GasFlamegraph, OpcodeViewer, FindingsPanel } from "@valve-tech/trace-sdk/components";
import { FullDebuggerLayout, RevertExplainer, CompactCallSummary } from "@valve-tech/trace-sdk/templates";
import type { CallNode, TraceFrame, GasProfile } from "@valve-tech/trace-sdk/types";API
Loaders (/loaders)
loadTraceFromHash(rpcUrl, txHash, options?)— fetch + normalize a trace from a live nodeloadTraceFromFile(path)— read a JSON trace dumploadTraceFromObject(obj)— normalize an already-parsed traceparseCallTrace/normalizeCallFrame— normalize a raw call framenormalizeStructLogs— normalize step-level opcode logs
Traversal (/traversal)
walkCallTree(root, visitor)— depth-first traversal with enter/exit hooksflattenCallTree(root)— array ofFlatFramewith depth metadatafilterByAddress(root, addr)/filterBySelector(root, sel)— subtree filtersfindRevertFrame(root)— first frame whose call revertedbuildGasProfile(root)— aggregated gas per contract / selector
Parsers (/parsers)
parseTokenDeltas(frame)— extract ERC-20 Transfer events asTokenDelta[]. Skips reverted call frames (and their subtrees) so output matches the on-chain receipt. Requires the trace to have been captured with the callTracerwithLog: trueoption.parsePrestateDiff(raw)— compute signed ETH balance changes per address from a prestateTracerdiffMode: truepayload, sorted by address.
Risks (/risks)
analyzeRisks(frame, options?)— walk the call tree and emitRiskFlag[]findings. Continues into reverted subtrees, tagging findings from there withreverted: trueso consumers can filter or visually distinguish.- Built-in rule:
DELEGATECALL_UNRECOGNIZEDflags any DELEGATECALL whose target isn't in the optionalwhitelistset. Pass known-good implementation contracts in the whitelist to suppress noise. BUILTIN_RULES/RiskRuleare exported for composing custom analyses.
Components (/components, React peer dep)
<CallTree>— interactive call tree with expand/collapse<GasFlamegraph>— proportional gas-cost flamegraph<OpcodeViewer>— step-by-step opcode trace with category coloring<FindingsPanel>— rendersanalyzeRisksoutput, grouped by severity<StateDiffPanel>— rendersStateDiff[]with balance/nonce/storage changes per address<FrameDetailPanel>— renders metadata for a singleTraceFrame(call type, gas, value, error, decoded I/O)
All components accept a classNames prop for full style override.
Templates (/templates, React peer dep)
Higher-order compositions of the components — drop-in views for common trace consumers:
<FullDebuggerLayout trace? opcodes? stateDiffs? risks? />— tabbed view (Call Tree / Opcodes / State / Risks). Each tab independently renders its empty state when data is missing; the Call Tree tab shows a<FrameDetailPanel>underneath after a frame is selected.<RevertExplainer frame />— locates the innermost reverting frame, surfaces itsrevertReasonprominently, and shows the breadcrumb chain from root to the reverter. Renders a success message when the transaction did not revert.<CompactCallSummary frame maxDepth? />— one-line-per-call terse summary with status badge + total-gas chip; suitable for embedding in logs, alerts, or chat messages.
License
MIT © Valve Tech
