# Debugging

Debugging smart contract transactions is an indispensable step in ensuring their reliability and security before they are deployed on the blockchain as well as understanding them thoroughly in production when planning and developing the next version of the protocol.

&#x20;When a transaction fails or behaves unexpectedly, developers need to trace the [execution flow](/use-cases/tracing/stack-traces.md), inspect state changes, and [examine gas consumption](/use-cases/tracing/stack-traces.md) at each step. Blocktorch's [local fork feature](/concepts/data-sources/local-forks.md) and [step debugger](/use-cases/debugging/step-debugger.md) provide environments where developers can simulate transactions, dig into call stacks, and interact with the contract's state. Furthermore, incorporating comprehensive logging (meaning adding relevant events that are emitted) within the contract can significantly aid in identifying issues quickly.&#x20;

As smart contracts handle valuable assets and sensitive operations, thorough debugging is paramount to maintaining trust and functionality in decentralized applications.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.blocktorch.xyz/use-cases/debugging.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
