Skip to content

Commit ee5a410

Browse files
committed
added docs for debugging with forc call
1 parent 56639a8 commit ee5a410

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

docs/book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
- [Debugging](./debugging/index.md)
6363
- [Debugging with CLI](./debugging/debugging_with_cli.md)
6464
- [Debugging with IDE](./debugging/debugging_with_ide.md)
65+
- [Debugging with Forc Call](./debugging/debugging_with_forc_call.md)
6566
- [Sway LSP](./lsp/index.md)
6667
- [Installation](./lsp/installation.md)
6768
- [Features](./lsp/features.md)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Debugging with Forc Call
2+
3+
The `forc call` command includes interactive debugging capabilities through the `--debug` flag, enabling developers to debug contract function calls step-by-step after transaction execution.
4+
5+
## Overview
6+
7+
When you add the `--debug` flag to any `forc call` command, it will:
8+
9+
1. Execute the contract function call as normal
10+
2. Automatically launch an interactive debugging session
11+
3. Allow you to step through the execution, inspect values, and set breakpoints
12+
4. Provide full access to the `forc-debug` interface
13+
14+
This integration seamlessly combines contract interaction with debugging, making it easy to understand what happens during contract execution.
15+
16+
## Basic Usage
17+
18+
Simply add the `--debug` flag to any existing `forc call` command:
19+
20+
```bash
21+
forc call <CONTRACT_ID> \
22+
--abi <ABI_PATH> \
23+
<FUNCTION_NAME> [ARGS...] \
24+
--debug
25+
```
26+
27+
## Example: Debugging a Contract Call
28+
29+
Let's say you have a contract with a function that performs some calculations:
30+
31+
```sway
32+
contract;
33+
34+
abi Calculator {
35+
fn factorial(n: u64) -> u64;
36+
}
37+
38+
impl Calculator for Contract {
39+
fn factorial(n: u64) -> u64 {
40+
let mut result = 1;
41+
let mut counter = 0;
42+
while counter < n {
43+
counter = counter + 1;
44+
result = result * counter;
45+
}
46+
result
47+
}
48+
}
49+
```
50+
51+
### Debugging the Factorial Function
52+
53+
```bash
54+
forc call 0x1234567890abcdef1234567890abcdef12345678 \
55+
--abi ./out/debug/calculator-abi.json \
56+
factorial 5 \
57+
--debug
58+
```
59+
60+
This command will:
61+
62+
1. Execute `factorial(5)` on the deployed contract
63+
2. Show the transaction result (return value: 120)
64+
3. Launch the interactive debugger with the transaction data pre-loaded
65+
66+
### Interactive Debugging Session
67+
68+
Once the debugger launches, you'll see the pre-buffered debugger prompt to start the transaction:
69+
70+
```text
71+
Welcome to the Sway Debugger! Type "help" for a list of commands.
72+
>> start_tx /var/folders/xz/5djvk4596k5c1fj2prcd0d880000gn/T/.tmpexrnFE.json /var/folders/xz/5djvk4596k5c1fj2prcd0d880000gn/T/.tmpuaPRtF.json
73+
```
74+
75+
You can now use all the [standard debugging commands](./debugging_with_cli.md#using-the-debugger).

0 commit comments

Comments
 (0)