๐Ÿ› Tronsell Wiki

Debugging Tools โ€” TRON Smart Contract Debugging Guide

Complete guide to debugging tools for TRON smart contracts and full nodes. Learn TronStudio, TronWeb debugging, log analysis, event tracing, and advanced debugging techniques.

๐Ÿ› Debugging Tools at a Glance
Primary DebuggerTronStudio
Transaction DebugTronScan + TronWeb
Log AnalysisJava-tron logs
Event TracingTronScan Events
VM TraceTVM trace output

๐Ÿ› Introduction to Debugging on TRON

Debugging is an essential skill for TRON developers. Smart contracts are immutable once deployed, and bugs can have serious consequences. Effective debugging helps you identify and fix issues before deployment, saving time, money, and reputation.

TRON provides a rich ecosystem of debugging tools, from integrated development environments with step-through debuggers to blockchain explorers that visualize transaction execution. This guide covers the complete debugging toolkit for both smart contract and full node development.

๐Ÿ’ก The Debugging Mindset

Debugging is not just about fixing bugs โ€” it's about understanding how your code behaves. Every failed transaction or unexpected output is an opportunity to learn. Use a systematic approach: reproduce, isolate, identify, fix, and verify.

๐Ÿ–ฅ๏ธ TronStudio: The IDE Debugger

TronStudio is the official integrated development environment for TRON. It includes a powerful built-in debugger that allows you to:

  • Set breakpoints โ€” Pause execution at specific lines of code.
  • Step through code โ€” Execute line by line, step into/over functions.
  • Inspect variables โ€” View current values of variables and contract state.
  • View call stack โ€” See the sequence of function calls that led to the current point.
  • Examine contract state โ€” Check storage, balances, and other state variables.
  • Test on local VM โ€” Debug in a simulated environment before deploying to testnet.
๐Ÿ’ก TronStudio Tips

Use conditional breakpoints to pause only when specific conditions are met. This is invaluable for debugging loops or complex state changes. Also, TronStudio's integration with TronBox allows you to run test suites and debug failing tests interactively.

๐Ÿ” Debugging with TronScan

TronScan is the primary blockchain explorer for TRON. It's an essential tool for debugging deployed contracts:

  • Transaction details โ€” View the full transaction receipt, including Energy and Bandwidth consumption.
  • Revert reasons โ€” See why a transaction failed (e.g., "revert: Insufficient balance").
  • Event logs โ€” View all events emitted by the transaction, with decoded parameters.
  • Contract code โ€” View verified contract source code and bytecode.
  • State changes โ€” See how the contract's state changed after the transaction.
  • Internal transactions โ€” Track contract-to-contract calls.
// Example: Checking a failed transaction on TronScan
// 1. Search for the transaction hash
// 2. Look for "Revert Reason" in the transaction details
// 3. Check the "Events" tab for emitted logs
// 4. Review "State Changes" to see what was modified
โšก Pro Tip

Use TronScan's "Contract" tab to interact with verified contracts. You can call read-only functions to inspect state, which is extremely helpful for debugging without sending transactions.

๐Ÿ”ง Debugging with TronWeb

TronWeb provides several debugging capabilities for developers:

  • Error messages โ€” TronWeb returns detailed error messages when transactions fail, including revert reasons.
  • Event listening โ€” Use contract.events to listen for events in real-time.
  • Transaction receipts โ€” Get full transaction receipts with tronWeb.getTransactionReceipt().
  • Logging โ€” Use console.log in your JavaScript test files to trace execution.
  • Simulation โ€” Use tronWeb.transactionBuilder to simulate transactions before sending.
// TronWeb debugging example
try {
  const tx = await contract.transfer(to, amount).send();
  console.log("Transaction success:", tx);
} catch (error) {
  console.error("Transaction failed:", error.message);
  // Check if error contains revert reason
  if (error.message.includes("revert")) {
    console.log("Revert reason:", extractRevertReason(error));
  }
}

๐Ÿ“‹ Event Logging for Debugging

Events are one of the most powerful debugging tools available. By emitting events at key points in your contract, you can trace execution flow and inspect variable values.

// Solidity: Debugging with events
event DebugLog(string message, uint256 value);

function transfer(address to, uint256 amount) external {
  emit DebugLog("Transfer started", amount);
  require(balance[msg.sender] >= amount, "Insufficient balance");
  balance[msg.sender] -= amount;
  emit DebugLog("Sender balance after deduction", balance[msg.sender]);
  balance[to] += amount;
  emit DebugLog("Receiver balance after addition", balance[to]);
  emit Transfer(msg.sender, to, amount);
}
๐Ÿ’ก Event Debugging Tips

Use temporary events for debugging โ€” you can remove them before deployment. For complex contracts, create a dedicated debug event that you can enable/disable with a flag. Events are gas-efficient and don't affect contract logic.

๐Ÿ“„ Node Logging & Monitoring

For full node development, Java-tron provides extensive logging capabilities:

  • Logback configuration โ€” Customize log levels (DEBUG, INFO, WARN, ERROR) for different components.
  • Transaction traces โ€” Enable detailed VM trace logging to see every operation executed.
  • Block logs โ€” Monitor block production and validation.
  • Network logs โ€” Track peer connections and message propagation.
  • Storage logs โ€” Monitor database operations and performance.
# logback.xml configuration for detailed debugging
<logger name="org.tron.core" level="DEBUG" />
<logger name="org.tron.common" level="DEBUG" />
<logger name="org.tron.consensus" level="INFO" />
<logger name="org.tron.db" level="INFO" />

๐ŸŽฏ Advanced Debugging Techniques

Beyond basic tools, these advanced techniques can help you tackle complex bugs:

  • VM Trace Analysis โ€” The TRON Virtual Machine (TVM) can output detailed execution traces showing every opcode and state change.
  • Gas Profiling โ€” Analyze Energy consumption to identify inefficient code paths.
  • State Diffing โ€” Compare contract state before and after transactions to see exactly what changed.
  • Replay Attacks โ€” Replay failed transactions on a local node with modified parameters.
  • Fuzzing โ€” Use automated fuzzing tools to generate random inputs that reveal edge-case bugs.
  • Time Manipulation โ€” In local tests, manipulate block timestamps to test time-dependent logic.
โšก VM Trace Example

Enable VM tracing in Java-tron by adding vm.trace.enable = true to config.conf. This will output detailed execution traces to the logs, showing every operation performed by the TVM during contract execution.

๐Ÿ† Debugging Best Practices

  • Reproduce the issue locally โ€” Always try to reproduce bugs in a local test environment first.
  • Use version control โ€” Commit often so you can bisect to find when bugs were introduced.
  • Write test cases โ€” For every bug you find, write a test that reproduces it.
  • Check the basics first โ€” Often the issue is a simple typo or off-by-one error.
  • Use the scientific method โ€” Form a hypothesis, test it, and iterate.
  • Document your findings โ€” Keep a debugging journal to track patterns and solutions.
  • Don't debug alone โ€” Rubber duck debugging (explaining the problem to someone else) often reveals the solution.
  • Take breaks โ€” Sometimes stepping away and coming back with fresh eyes solves the problem.
๐Ÿ’ก Debugging Checklist

Before diving deep: 1) Check transaction fee limits, 2) Verify contract address, 3) Confirm you're calling the right function, 4) Check parameter types and values, 5) Review access control modifiers, 6) Verify contract state with a read-only call.

โ“ Frequently Asked Questions

What debugging tools are available for TRON smart contracts?

TRON developers have access to several debugging tools: TronStudio (IDE with built-in debugger), TronWeb (for transaction debugging), TronBox (test and debug), TronScan (transaction explorer with event logs), and various logging and monitoring tools. For node development, Java-tron includes extensive logging and JMX monitoring capabilities.

How do I debug a failed TRON transaction?

To debug a failed transaction: 1) Check the transaction receipt on TronScan to see the revert reason and error message. 2) Review the contract's event logs to understand what happened. 3) Use TronWeb to simulate the transaction with tracing enabled. 4) In TronStudio, step through the contract code with breakpoints. 5) Check the node logs for additional error details.

What is TronStudio and how does it help with debugging?

TronStudio is an integrated development environment (IDE) for TRON that includes a built-in debugger. It allows developers to set breakpoints, step through contract code line by line, inspect variable values, and view the call stack. It supports both local contract testing and interaction with testnet contracts, making it invaluable for identifying and fixing bugs.

How can I use events for debugging TRON contracts?

Events are a powerful debugging tool. By emitting events at key points in your contract, you can track the flow of execution, monitor state changes, and inspect variable values. You can view emitted events on TronScan, use TronWeb's event listeners, or query events through the node API. Events provide a non-intrusive way to gain visibility into contract behavior.

What are common debugging techniques for TRON smart contracts?

Common debugging techniques include: using event logging to trace execution, leveraging TronStudio's interactive debugger, analyzing transaction reverts with TronScan, using console.log in TronWeb tests, checking node logs for VM errors, comparing contract bytecode with source code, and using the TRON VM's trace output for detailed execution analysis.

How do I debug a full node issue?

For node debugging: 1) Check the node logs (Java-tron outputs detailed logs). 2) Enable JMX monitoring to track JVM performance. 3) Use database inspection tools to check storage integrity. 4) Monitor network connectivity and peer status. 5) Enable VM trace for transaction execution issues. 6) Use TronWeb to query the node's API directly to test specific endpoints.

โšก Build with Tronsell Energy

Integrate Tronsell Energy into your zero-fee USDT transfer contracts. Simple API, instant delivery.