China-based development group NewEconoLabs has announced the release of NeoRay, a web-based smart contract debugger for the NEO blockchain, alongside a brief tutorial for its use. NEL states that NeoRay is a “one-stop debugging tool” intended to help developers troubleshoot their smart contracts. NEL’s NeoRay is based on its previously released NeonDebug smart contract toolkit, but with various interface and usability improvements, including online community support, one-click TestNet GAS claims, and improved ease of setup.

NeoRay has native Chinese language support with limited English functionality at this time. Google Chrome’s Translate function, or translation plugins for other web browsers, can be very useful for English-speaking users who are navigating the NeoRay interface for the first time.

NeoRay Components

NeoRay consists of three components in one: an online NEO wallet, a C# code compiler, and a “transaction result parser” which serves to analyze the results of calling a smart contract’s function. As NEL notes, “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.”

When a bug is foundthat is, the execution of a contract call’s results vary from the contract developer’s expectationsNeoRay provides a transaction log containing complete execution data, and allows them to correlate the individual run steps in NEO’s virtual machine with the C# code that was compiled to create the instructions. After seeing how the NEO virtual machine executes the code line by line, smart contract authors can identify issues and modify their C# source code, re-compile the C# code into another virtual machine instruction set, re-publish the contract, and try again.

NEL warns users 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.” Developers wanting to create a closed-source smart contract should test and troubleshoot with NEL’s offline NeonDebug toolkit.

Compiling, Publishing, and Debugging: A Brief Guide

The first step to publishing one’s own smart contract on the NEO blockchain is writing your contract’s source code with proper syntax. Although NEO offers compilers supporting several mainstream programming languages, NeoRay currently only supports C#. NEL recommends writing the initial code in Microsoft’s Visual Studio development environment to check for syntax errors, and then copy/pasting the code into the NeoRay compiler.

The second step is deploying the compiled smart contractwhich is now an AVM instruction set that the NEO virtual machine can understandto the NEO blockchain’s TestNet. Doing so will usually require 500 TestNet GAS, which can be obtained once per day by clicking the blue button on the top left of the page after logging in with a NEO wallet.

Once deployed, contracts can be debugged using the NeoRay software. Contracts may be tested via the “test run” function, which reads the contract’s data without writing to the blockchain, and the “call transaction” function which writes to the blockchain and directly interacts with the contract’s data.

As NEL explains, “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”. Once confirmed, transactions that interact with a smart contract published using NeoRay will contain full contract execution results. Results that differ from expected can be traced back to their origins, the raw code in the .avm instruction set, which NeoRay correlates with the original C# source code. After rewriting or redesigning the C# source code, it can be compiled and published again for another try.

Microsoft Visual Studio Community 2017 is available from Microsoft for free.

NEL’s full NeoRay announcement and tutorial can be viewed at the following link: https://medium.com/neweconolab/with-neoray-neo-smart-contract-development-has-never-been-easier-edad41cc3ae6