A Detailed Explanation to NEO Smart Contracts Debugging
It’s troublesome to debug NEO smart contracts. When we NEL develop NNS, we find that existing tools cannot support us to develop so complex smart contracts.
So we have developed our own set of smart contracts debugging tools.
The 1st step: to compile smart contracts
Install neondebug.
Get the code for neondebug from the following GitHub link and compile it.
https://github.com/NewEconoLab/neondebug
You will get a brand new neon.exe
Replace the old noen.exe with this new one.
So how to replace it? Please refer to the following steps. First, remove the previous path of neon.exe, and then change into the path of neondebug.
Why need to install neondebug?
Neondebug exports one additional map.json file to achieve mapping from avm to source code, meanwhile, put avm abi cs map.json together according to hash.
For example to produce
Scripthash will be used directly to collect relevant files.
Check compiling results
Use neondebuggui’s “ load avm from file “ button to load the avm file that’s just produced.
You could check it. After checking, you could use NEONDEBUGGUI’s debugging tools to debug transactions which use this script.
Open source smart contracts
Using “upload this to server” button, we can upload smart contract code to servers, where everyone could get this contract information.
Using “ load from server” button, we could check contract information on the server according to scripthash.
the 2nd step:to produce a transaction
install neo-gui-nel
Get the code of neo-gui-nel in the following GitHub link and compile it.
https://github.com/NewEconoLab/neo-gui-nel
You will get a NEL customized version of NEO-GUI.
At the first glance, you may think this version does not look any different. However, to release the smart contract, you will find a difference. Please note that neo-gui-nel is configurated on the testnet by default.
NEL customized version of NEO-GUI is the first one to support NEP4(dyncall) contract.
the 3rd step: debugging
Invoke a contract
Calling the contract, an Array can be added to the NEOGUI custom version. Imagine this smart contract Main (string, object [] args), where args [0] is a string [] This requires a nested array inside an array, there is no way for neo-gui to call such a contract now.
Debug and test run a contract
After clicking” test run”, you can debug it.
According to default configuration of Neo-gui-nel, after you click test run, you will get a file”oxoo” in this directory. By using it, you can finish debugging NEO smart contracts.
Use the NEONDEBUGGUI’s Debug Transaction tab
LoadFromFile button, open this 0x00 file
You get a tool that has every step of the detailed execution of a smart contract.
And through this tool,you can correspond to the source code, observe the implementation of the stack details and the details of each data.
So you can fully understand how this test is run
Debug a transaction
Send a transaction and wait a minute for it to be confirmed.
You can find the file corresponding to this transaction in the fulllog directory. Open it, you can debug the transaction’s actual operation details on the chain.
the 4th step: more functions and more convenience
1. As long as someone uploads a smart contract once, everyone can see the source code when debugging at any time
2. We have a crawler, which is ready to upload the testnet contract’s log file to the server . Even if you do not have the NEO-GUI-NEL installed, you can debug using the loadformserver button as long as you know the transaction id.
3. We will develop a pure web version of the debugging tools in the future.
4. We will also synchronize the main network data and upload it to the server in the future.