Debugging smart contracts
What you will need
You will need to use Neo Debugger to debugg , and Neo Blockchain Toolkit to assist you along the way.
To install these tools directly in your VSCode, visit the Neo Smart Contract Debugger - Visual Studio Marketplace and Neo Blockchain Toolkit - Visual Studio Marketplace.
You must have four files for the debugging process to work properly: the smart contract, the .nef file, the .manifest.json file, and the .nefdbgnfo file.
If you have already compiled your code, proceed to the next step. To compile the files, ensure that your smart contract script file is not empty and that the functions you’re calling are functioning correctly.
On the command line, write:
now you should have the files .nef and manifest.json.
Generating the .nefdbgnfo File
To generate the .nefdbgnfo file, use the following command in your command line:
You should now have the .nefdbgnfo file.
If you prefer using a Python script to generate the files, compile the smart contract by passing the
debug=True parameter like this:
Creating the launch.json File
You will need to create a folder named
.vscode at the root of your project. Inside that folder, create a file named
After that, in Visual Studio Code, go to the “Execute” menu, and you will see an option to “Add Configuration.” Choose “Neo contract: Launch,” which will generate the base content of the
launch.json file. It should look like this:
Next, add the “operation” field inside “invocation”, like this:
Configuration of the debugger
At first, change the value of ‘program’ to the path of your smart contract, If you’re using Windows remember to change the ”\” for ”/” it to work properly.
Change the value of the ‘operation’ field to the name of the function you want to debug, and change the value of ‘args’ to the arguments of that function if there are any.
launch.json file with the configuration you just wrote in the debugging area of Visual Studio Code, and the debugging process should start.
If you want to know more
To check for additional specifics, take a look at the documentation from Neo Debugger.