Nethereum.Blazor.Solidity
NuGet:
Nethereum.Blazor.Solidity| Source:src/Nethereum.Blazor.Solidity/
Nethereum.Blazor.Solidity
Blazor components for EVM transaction debugging with Solidity source mapping, step-through execution, and Monaco editor integration.
Overview
Nethereum.Blazor.Solidity provides an interactive EVM debugger for Blazor Server applications. It replays Ethereum transactions through the Nethereum EVM simulator (or via debug_traceTransaction RPC), matches deployed bytecode to Solidity source files, and presents a step-through debugging experience with source highlighting, stack/memory/storage inspection, and opcode-level navigation.
Key Features
EvmDebuggercomposite component with control bar, opcode list, source panel, and state panelIEvmDebugService/EvmDebugServicereplays transactions via EVM simulation with fallback todebug_traceTransactionopcode tracer- Source map matching via
FileSystemABIInfoStorage.FindABIInfoByRuntimeBytecode()for automatic Solidity file discovery SolidityCodeViewerwraps the Monaco editor via JavaScript interop for syntax-highlighted source display with line highlighting- Step controls: start, end, step forward/back, next/previous source line, go-to-step
- State inspection tabs: Stack, Memory (32-byte chunks), Storage (key/value pairs), Call Info (contract, caller, depth, gas, opcode, decoded parameters)
AddSolidityDebugger()DI extension for service registration
Installation
dotnet add package Nethereum.Blazor.Solidity
Targets net10.0.
Dependencies
- Nethereum.EVM -
EVMDebuggerSession,ProgramTrace,ProgramInstructionsUtilsfor EVM simulation and trace stepping - Nethereum.Web3 - RPC client for
debug_traceTransactionfallback and transaction/receipt retrieval
Quick Start
1. Register Services
using Nethereum.Blazor.Solidity;
builder.Services.AddSolidityDebugger();
This registers IEvmDebugService as a scoped EvmDebugService.
2. Include Static Assets
In your _Host.cshtml or App.razor:
<script src="_content/Nethereum.Blazor.Solidity/solidity-monaco-interop.js"></script>
The Monaco editor is loaded from a CDN by the interop script.
3. Use the Debugger Component
@using Nethereum.Blazor.Solidity.Components
<EvmDebugger TransactionHash="@txHash"
Web3="@web3"
ABIDirectory="@abiDir" />
@code {
private string txHash = "0xabc...";
private Nethereum.Web3.Web3 web3;
private string abiDir = "/path/to/abi-output";
}
Components
EvmDebugger
Main composite component that orchestrates the debugging session. Accepts a transaction hash, replays it, and renders four sub-components in a split layout.
Parameters:
TransactionHash(string) - Transaction hash to debugWeb3(Nethereum.Web3.Web3) - Web3 instance for RPC callsABIDirectory(string) - Path to directory containing compiled ABI/bytecode output (Forge, Hardhat, etc.)
DebugControlBar
Navigation controls for stepping through execution trace.
- GoToStart / GoToEnd - Jump to first or last trace step
- StepBack / StepForward - Move one opcode at a time
- PrevSourceLine / NextSourceLine - Jump to the next step that maps to a different source location
- GoToInputStep - Jump to a specific step number
Displays the current step index, total steps, and current opcode.
DebugOpcodeList
Scrollable list of all opcodes in the execution trace. Each entry shows the program counter, opcode mnemonic, and gas cost. The current step is highlighted and auto-scrolled into view.
DebugSourcePanel
Displays Solidity source files with the current execution line highlighted. When multiple source files are involved (e.g., imported contracts), file tabs allow switching between them. Uses SolidityCodeViewer internally.
DebugStatePanel
Tabbed panel showing EVM state at the current execution step:
| Tab | Content |
|---|---|
| Stack | Current stack values (top-down, hex-encoded) |
| Memory | Memory contents displayed in 32-byte rows |
| Storage | Key/value pairs written to storage at the current contract |
| Call Info | Current contract address, caller, call depth, remaining gas, current opcode, and decoded function parameters |
SolidityCodeViewer
Monaco editor wrapper via JavaScript interop (solidity-monaco-interop.js). Provides:
- Solidity syntax highlighting
- Read-only display mode
- Line highlighting for current execution position
- File registration and switching for multi-file debugging sessions
Services
IEvmDebugService
public interface IEvmDebugService
{
bool IsAvailable { get; }
Task<EvmReplayResult> ReplayTransactionAsync(string transactionHash);
}
EvmDebugService
Replays a transaction through the following pipeline:
- Fetches the transaction and receipt via
eth_getTransactionByHash/eth_getTransactionReceipt - Runs the transaction through
EVMSimulatorto produce aProgramResultwith full execution trace - If an
ABIDirectoryis configured, callsFileSystemABIInfoStorage.FindABIInfoByRuntimeBytecode()to match deployed bytecode against compiled artifacts - When source maps are found, maps trace steps to Solidity source locations and loads source file contents
- Falls back to
debug_traceTransaction(opcode tracer) when EVM simulation is not available - Returns an
EvmReplayResultcontaining theEVMDebuggerSession, step count, source files, and error information
EvmReplayResult
public class EvmReplayResult
{
public EVMDebuggerSession Session { get; set; }
public int TotalSteps { get; set; }
public bool IsRevert { get; set; }
public bool HasSourceMaps { get; set; }
public string Error { get; set; }
public List<string> SourceFiles { get; set; }
public Dictionary<string, string> FileContents { get; set; }
}
Source Map Matching
The debugger automatically discovers Solidity source files when an ABI output directory is provided (e.g., Forge's out/ or Hardhat's artifacts/). The matching process:
FileSystemABIInfoStoragescans the directory for compiled contract artifacts containing runtime bytecode- For each contract in the trace, the deployed bytecode is compared against the stored artifacts
- When a match is found, the source map and source file paths from the compilation output are used to map program counter values to source locations
- Source files are loaded and displayed in the
DebugSourcePanel
This works with standard Solidity compiler output formats (Forge, Hardhat, solc --combined-json).
Related Packages
Dependencies
- Nethereum.EVM - EVM simulator, debugger session, and trace infrastructure
- Nethereum.Web3 - RPC client for transaction retrieval and debug tracing
See Also
- Nethereum.EVM - EVM simulator and instruction set
- Nethereum.Blazor - Blazor wallet integration and authentication
- Nethereum.Explorer - Blazor Server block explorer that embeds the debugger