Skip to content

Using the VSCode Solidity Debugger

Matthew Little edited this page Nov 8, 2018 · 5 revisions

Install Prerequisites

Debugging using only Solidity

Option 1) Debug a single .sol file containing a single contract

  • Ensure no Folders or Workspaces are opened in VSCode and open your .sol file.
  • The contract must define a parameterless constructor function (so that it can be automatically deployed).
  • This constructor function can call other functions in your contract.
  • When debug is started the contract is deployed and its constructor function will be ran. Any breakpoints set in the constructor or functions that it calls will be hit.

Option 2) Debug Solidity codebases with multiple contracts

  • Open the folder containing .sol files with VSCode.
  • Define a contract titled Main with a parameterless constructor function.
  • This entry point contract can deploy your other contract(s) in its constructor function.
  • When debug is started the Main contract is automatically deployed and its constructor function will be ran.

Debugging using Unit Tests

Setup a unit test project

First, follow the quick guide to setting up a Solidity test project using Meadow.

Install the C# Extension for VSCode

https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp

Configure launch.json

  1. Open your project in VSCode and select the debug panel (located on the left vertical menu bar).
  2. At the top left debug dropdown (next to the green play button), select "Add Configuration..."
  3. Inside the .vscode/launch.json file, add the following configuration:
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "solidityMeadow",
            "request": "launch",
            "name": "Debug Solidity (via unit test run)"
        }
    ]
}

Set breakpoints

Open a .sol source file from your contracts directory and set breakpoints in a function that gets executed by your C# unit tests.

Launch the debugger

Select the debug panel again, ensure the correct configuration is selected, and click the green play button.

The unit tests will be executed and your breakpoint will be hit.

Solidity Debugger Extension