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.
When you add the --debug
flag to any forc call
command, it will:
forc-debug
interface This integration seamlessly combines contract interaction with debugging, making it easy to understand what happens during contract execution.
Simply add the --debug
flag to any existing forc call
command:
forc call <CONTRACT_ID> \
--abi <ABI_PATH> \
<FUNCTION_NAME> [ARGS...] \
--debug
Let's say you have a contract with a function that performs some calculations:
contract;
abi Calculator {
fn factorial(n: u64) -> u64;
}
impl Calculator for Contract {
fn factorial(n: u64) -> u64 {
let mut result = 1;
let mut counter = 0;
while counter < n {
counter = counter + 1;
result = result * counter;
}
result
}
}
forc call 0x1234567890abcdef1234567890abcdef12345678 \
--abi ./out/debug/calculator-abi.json \
factorial 5 \
--debug
This command will:
factorial(5)
on the deployed contract Once the debugger launches, you'll see the pre-buffered debugger prompt to start the transaction:
Welcome to the Sway Debugger! Type "help" for a list of commands.
>> start_tx /var/folders/xz/5djvk4596k5c1fj2prcd0d880000gn/T/.tmpexrnFE.json /var/folders/xz/5djvk4596k5c1fj2prcd0d880000gn/T/.tmpuaPRtF.json
You can now use all the standard debugging commands .