NEL

In the past, NEL released the neon_debug_gui debugging tool for smart contract debugging on NEO. We recently released its online version called “NeoRay”, which is a super tool that integrates the compilation, deployment, invocation, and debugging of smart contracts.

If you are already familiar with our previous debugging tools and processes, then you can skip this article and use this online debugging tool directly.

https://neoray.nel.group

Why did we want to do it?

We did a similar debugging tool before, but later we found that these tools are too complicated for the novice, as they need to learn additional things such as configuration, use process, and understanding the implementation of contract debugging. So we made a one-stop debugging tool that helps developers quickly get into the debugging process from contract code. What’s better is that it doesn’t require you to configure the environment, you just open the web page and use it. And the whole tool is online, which means that when you encounter a problem that is difficult to solve, you can ask someone to help you see where the problem is.

2. What does it do?

This debugger consists of a wallet, a simple code compiler, and a transaction result parser that is connected to NEO TestNet. The debugging tool is composed by three parts: contract compilation deployment, contract calling, and contract debugging. Each part is placed on a single page.

Contract compilation deployment

On the contract compilation deployment page, there are two functions: compiling the contract code and deploying the compiled contract code to the chain.

Our online compiler can compile the C# language contract code into a deployable AVM file, but it cannot be compiled when the code has a syntax error. We recommend that you write the code first in visual studio to ensure that there are no syntax errors and then paste it into the web page to compile.

ou can also load the saved contract code on our server via contract hash or directly load the contract code you have deployed. It should be noted that we will save the contract code deployed by the debugging tool on the server for contract debugging. Anyone can access the contract source code via hash. So using this tool means that your code will be open sourced.

Once the contract is compiled, it can be deployed directly to the chain. You need to fill in some contract information, which is the same as that on the neogui. This information will be displayed when you open the contract code again. Wait for the contract deployment transaction to be confirmed on the chain, then you can use the transaction call contract.

You can see the confirmation status of the contract deployment transaction in the operation log and call the contract after the transaction is confirmed.

Contract call

On the contract call page, there are two functions: test run contract and call contract . Before that, you need to fill in the target contract hash.



Both test run contract and call contract need to be filled in with the transaction parameters. The transaction parameters include which function in the contract you need to call and the parameters that need to be passed to it. The specific method of filling in the parameters will be explained by a special explanation document, click on the help.

“Test run” does not need sending a transaction, does not change the data on the chain, returns the result immediately, but cannot perform the verification operation. It’s generally used to query the data in the contract. To debug a contract, you need to use “call transaction” and send a transaction to call the contract to see how the contract is executed in the real world.

Contract debugging

When you debug a contract, you are actually debugging the execution of a contract at a certain transaction. Therefore, you can only debug it after the transaction is confirmed . It should be noted that only the transactions that use the contract deployed by our debugging tool in our debugging tool can be debugged, because the data needed for debugging needs to be collected in advance, and the operation of collecting data needs to be initiated by the debugging tool.

You need to fill in (or select) a transaction ID before you can query its execution data.

Check the log/notify data before debugging. If the data is correct, the contract runs normally and there is no need to debug. If an error occurs, you need to debug the contract by clicking on the AVM to view the contract run steps.

In the AVM column you will see every step of how the node executes contract, the right area is the code corresponding to these operations, and the left side is the corresponding memory stack data. By moving the AVM’s cursor, both the code and the stack data will change. The whole debugging process is similar to marking the break point in the code when we debug the program. The difference is that every step of the operation here will be marked with break points, you can clearly see the execution logic and state inside the node.

The data in the stack is hexadecimal bytecode, which humans cannot read directly. The Value tool in the lower left corner can help you convert the data stream in the stack into a string, number or address.

3. How can I use it?

First, you have to have a NEO wallet. If not, you can create a new wallet on our login page.

Make sure you have enough TestNet GAS in your wallet (generally deploying a contract costs 500 GAS). You can apply for TestNet GAS in our debugging tool. Each wallet can apply for 500gas per day at maximum. If you need more GAS, you can only leave a message on our developer forum.

Second, you need to enter the smart contract code into the debugging tool, and click and compile the code into avm that can be deployed.

If the compilation fails, it should be that the code syntax is incorrect or the necessary references are missing, and the prompt below will be displayed. There is no way to prompt for an explicit number of error lines.

Third, deploy the compiled contract code to the network and wait for the transaction to be confirmed.

Fourth, choose a contract that you have deployed or directly enter the contract hash to call other people’s contracts.

Then fill in the call parameters, click on the call transaction to send a transaction that calls the contract. This transaction may involve multiple calls among multiple contracts. Make sure that all contracts must be deployed using the debugger, otherwise the code will not be visible during debugging. If you just try to query the value stored in the contract, you can run it directly.

Fifth, select a transaction you have already issued to debug or directly enter the TXID to debug the transaction. In the middle of the screen you can see AVM, Careinfo and log/notify.

Sixth, check the log/notify information to see the complete contract execution results. If the data returned by the transaction is not as expected, return to the AVM to find the problem.

Seventh, click on AVM to view the corresponding contract code and stack data.

AVM is every step of the virtual machine’s execution of the contract. It doesn’t matter if you don’t understand it. Click on a single step in the AVM to view the corresponding code and stack data. Then click on the AVM and use the ↑↓ arrow to move the cursor to see how the code is executed line by line. If the contract execution is problematic, the final execution step will return an error, or you may find that the code execution order or stack data is inconsistent with your design.

By observing these execution states, you can complete your own contract debugging, then go back to the starting point, modify the code, resend the contract, and debug until it exactly matches your design.