Learning SmartX: How to Debug a Smart Contract?
At 2018-11-04 By Yue Zhao

1. Three different versions of SmartX

SmartX is the officially released version that provides the most advanced features and stable development experience.

SmartX beta is the beta released version that includes the newest features. But there may be some bugs existed, which will be fixed in the SmartX community edition first.

SmartX debug is the open-source community edition. Login function has been removed for more convenient development.

2. Start debugging

2.1 Debug procedure

Step1 - Create a python project

Select the python language and blank template. Copy the code in OEP4Sample.py to editor.

step 1.png

step 1.png

Step2 - Compile

Clicking the "Compile" button to compile the smart contract. ABI and AVM will be generated and Opcode will be displayed at the bottom.


Step3 - Set a breakpoint

Clicking on the left side of the line number, a red breakpoint will appear.


Step4 - Debug run

Firstly, Select run function, choose the type of the parameters, and fill in the parameters.

Secondly, click the "Debug Run" button.


After clicking the "Debug Run" button, "Debug run" will be "Waiting".

Step5 - Use the debug panel

Use the navigation panel to debug.

debug panel.png

From the left to the right:

Continue(jump to the next breakpoint), Debug Stop, Step Over Line, Step Over Opcode, Clear (clear the window)

2.2 Debug panel

The panel displays basic information about the current smart contract.


From the left to the right:

Logs: display execution result

Evaluation Stack: temporarily store the data it is currently executing

Alt Stack: store all variables. The locals read variables from alt stack

History: display the history of execution of OP code

Locals: display local variables associated with the current context.

Storage: the database of the smart contract

2.3 Change parameters in console

How to change variable

Change a value in parentheses and the value of the corresponding variable will be changed.

change locals.png

How to change storage

You can add or delete any key and its corresponding value in storage console.

change storage.png

How to use transform tool in debugging

Select a function you want to use and fill the data into space.

Function list of Tool panel

tool panel.png