The AlgoKit AVM VS Code Debugger extension enables line-by-line debugging of Algorand smart contracts on the AVM, whether written in TEAL directly or compiled from Puya. It leverages AVM simulate traces and source maps to provide a seamless debugging experience. For detailed setup instructions, see the Detailed Usage section.
The core functionality is built on top of the AVM Debug Adapter. Additionally, a set of companion utilities are provided in the TypeScript and Python versions of algokit-utils
, making it easier for developers to set up the required prerequisites and run the debugger.
To skip straight to the list of features, go to Features.
Before you can use the AVM Debugger extension, you need to ensure that you have the following installed:
- Visual Studio Code: Version 1.80.0 or higher. You can check your version by going to
Help > About
in VS Code. - Node.js: Version 18.x or higher. The extension is built with Node.js. Check your Node.js version by running
node -v
in your terminal/command prompt.
Below is a bare-bones example of how to get started with the AVM Debugger extension in an AlgoKit based project relying on algokit-utils
.
-
Enable debugging in algokit-utils:
// In your main file (TypeScript) import { config } from 'algokit-utils-ts' config.configure({ debug: true, traceAll: true })
or
# In your main file (Python) from algokit_utils.config import config config.configure(debug=True, trace_all=True)
-
Interact with your smart contract: Perform an application call using
algokit-utils
. -
Start debugging:
- Open the AVM simulate trace file (ends with
.trace.avm.json
) - If using an official
algokit-python-template
, execute theDebug TEAL via AlgoKit AVM Debugger
launch configuration. Otherwise, create a new VSCode launch configuration of typeavm
(which will automatically set recommended defaults). - The extension can also be invoked via the debug icon in the editor (visible in top right corner when viewing a trace file) or using the
Debug AVM Trace File
command from the Command Palette. - The debugger will guide you through the process of selecting the correct source files and traces and will initiate the debugging session.
- Open the AVM simulate trace file (ends with
Pro Tip: Use the
Clear AVM Debug Registry
command if you need to reset your sourcemap selections or if you're experiencing mapping issues.
To learn more about the features and how to use them, continue reading below.
The AVM Debugger extension automatically detects and operates on the following files:
- Simulate Traces. A
*.trace.avm.json
file that contains the traces obtained from algod'ssimulate
endpoint. This serves as an entry point for the debugger. See an example here. - Source Maps. Source maps for the programs executed within the trace. These can be either a
Additionally, it maintains a file named
sources.avm.json
in the root of your project (defaults to.algokit/sources/sources.avm.json
), which contains a mapping of the compiled source maps to the original source code.
If you are aiming to debug TEAL code in a project generated via algokit init
, follow the steps below.
# Place this code in a project entry point (e.g. main.py)
from algokit_utils.config import config
config.configure(debug=True, trace_all=True)
// Place this code in a project entry point (e.g. index.ts)
import { config } from 'algokit-utils-ts'
config.configure({ debug: true, traceAll: true })
NOTE: Storing debug traces is not possible in browser environments, your contract project needs access to filesystem via
node
. If you wish to extract simulate traces manually from an app running in a browser that usesalgokit-utils-ts
, refer to algokit-utils-ts docs.
Alternatively, if you are using algokit-utils
in a project that is not generated via algokit init
, refer to the following utilities:
Depending on the language you are using, you can use the above utilities to generate source maps
for your TEAL as well as debug traces
obtained from algod's simulate
endpoint (which is also an entry point for this debugger extension). Alternatively, you can use the utilities as a reference for obtaining source maps and traces without algokit-utils
.
To obtain puya source maps, ensure to set the --output-source-map
flag to true
when compiling your smart contract with puya
and using the latest version of the puya
compiler.
The extension supports the following launch configurations:
- Debug Session from a Simulate Trace File
This is the simplest way to launch a debug session. The simulateTraceFile
property in the launch configuration specifies the path to the simulate trace file *.trace.avm.json
. The sources.avm.json
file is automatically selected from the working directory. If there is more than one sources.avm.json
file in the working directory, you will be prompted to choose one. The debugger expects the launch configuration to be of type avm
(Algorand Virtual Machine).
{
"version": "0.2.0",
"configurations": [
{
"type": "avm",
"request": "launch",
"name": "Debug TEAL Program with auto-picked sources",
"simulateTraceFile": "${workspaceFolder}/debug_traces/simulate-response.trace.avm.json",
"stopOnEntry": true // optional
}
]
}
- Debug Session Using Specific Debug Config Paths
If you want to target a specific sources.avm.json
file, you can specify the path to the file using the programSourcesDescriptionFile
property in the launch configuration.
{
"version": "0.2.0",
"configurations": [
{
"type": "avm",
"request": "launch",
"name": "Debug TEAL Program from hardcoded sources and traces",
"simulateTraceFile": "${workspaceFolder}/debug_traces/simulate-response.trace.avm.json",
"programSourcesDescriptionFile": "${workspaceFolder}/.algokit/sources/sources.avm.json",
"stopOnEntry": true // optional
}
]
}
- Debug Session with Interactive File Picker
The extension also offers an interactive picker for simulation trace files. The PickSimulateTraceFile
command can be used to interactively select a simulation trace file from the working directory. The following launch configuration will also prompt a second picker for the sources.avm.json
file if it detects more than one sources.avm.json
file in the working directory.
{
"version": "0.2.0",
"configurations": [
{
"type": "avm",
"request": "launch",
"name": "Debug TEAL Program with interactive trace and source picker",
"simulateTraceFile": "${workspaceFolder}/${command:PickSimulateTraceFile}",
"stopOnEntry": true // optional
}
]
}
Please note the limit for max visible items in the extension picker is 100. If you have more than 100
sources.avm.json
files in the working directory, consider using theprogramSourcesDescriptionFile
property to specify the path to a specific file.
The following will become available within the IDE after the extension is installed.
The extension provides the following commands that can be accessed via the Command Palette (Ctrl+Shift+P / Cmd+Shift+P):
Command | Description |
---|---|
Debug AVM Trace File |
Initiates a debugging session from an open trace file. Can also be triggered via the debug icon when viewing a trace file |
Clear AVM Debug Registry |
Resets the AVM debug registry file (sources.avm.json) - useful when you want to start fresh with sourcemap selections |
Edit AVM Debug Registry |
Opens the AVM debug registry file for manual editing |
Configure the debugger behavior through VS Code settings:
Setting | Description | Default |
---|---|---|
avmDebugger.debugAdapter.port |
Port number for the debug adapter when running in server mode. Leave empty for inline mode | null |
avmDebugger.defaultSourcemapRegistryFile |
Custom path to the sources.avm.json registry file | .algokit/sources/sources.avm.json |
Tip for Beginners: Start with the default settings. The inline debug adapter mode (default when
debugAdapter.port
is not set) is perfect for most use cases.
Advanced Usage: Set
debugAdapter.port
when you need to run the debug adapter as a separate process, which can be useful for development or debugging of the extension itself.
This document outlines the features supported by the AVM debugger. Screenshots and features are based on the VS Code client.
This is an open source project managed by the Algorand Foundation. See the contributing page to learn about making improvements, including developer setup instructions.
If you have any issues or feature requests, please open an issue.