Foreword

NeoRay is a tool developed by NEL to facilitate NEO contract development. Since the launch of this tool, it has been well received by many developers and helped a vast number of NEO contract developers. I have also been using this tool to develop and debug NEO contracts.

Recently, NEL has launched a new version of NeoRay, which has added the contract development of the Python language and humanized some operational processes. As a NEO contract development enthusiast, I can’t wait to try this new version. The experience is still great, the page looks simpler and clearer, and the contract call part is more user-friendly.

Because compared with the old version, there are still very large changes to the new version, and the pages and processes are very different. As an early adopter, it is still necessary to record the experience of trying it. Hopefully, it could be of some help to other NEO developers.

Main body

0x01 Log-in

NeoRay 2.0 no longer uses the private key or nep6 wallet login to deploy and call the contract, but instead uses the TEEMO extension wallet launched by NEL. You need to install the extension wallet before using NeoRay2.0. Otherwise, the following prompt will appear:

Here is a description of the Teemo extension wallet:

0x02 Page function introduction

The overall page of the new version of NeoRay is as follows. There are five function buttons on the left: file browsing, contract deployment, contract call, contract debugging, and support. It also provides a button to switch back to the old version of NeoRay.

0x03 Write or load a contract file

There are three ways to import a contract file in the file browsing module. The first is to add local files; the second is to create new files directly online; the rest is to load contracts deployed by other developers through contract hash. You can choose according to your own needs. Here I use the first way to do the demo. I imported a local test contract, as shown below:

0x04 Contract deployment

When the contract is written or imported, we need to compile and deploy the contract. Click the “contract deployment” button on the left to enter the deployment page. First, click the “compile” button. If the contract is written correctly, the output box will display the contract’s hash. If the contract has an error, it will prompt “compiling failed.” At present, the reasons for the failure are not detailed enough, and it is hoped that future updates will provide detailed failure reasons.

Some parameters when setting contract deployment. “Dynamic call” refers to whether there exist calls to variable contracts in the contract. For example, if a B contract is called, but the B contract cannot clarify its hash value when the contract is deployed, then the dynamic call is needed. “Create storage area “ means that the contract uses the storage function. “Accept Payment” means whether the contract can accept the transfer of assets from other addresses.

It should be noted that different parameter selections will bring different charges. At present, “dynamic call” will cost 500gas, and “create storage area” will cost 400gas.

After clicking the contract deployment button, the Teemo wallet will pop up a window to request a signature, click “agree”

0x05 Contract call

Wait for the contract deployment transaction to be confirmed through Teemo

Once the transaction is confirmed, click on the contract call button on the left side of NeoRay2.0 to the contract debugging module. Next, I will introduce the meaning and usage of some parameters under this module.

System fee: The contract on the NEO blockchain is charged according to the instructions invoked. Although there is a free quota of 10gas, some complicated operations may exceed the quota of 10gas. So if the contract you are calling is too complicated and the cost exceeds 10gas, you will need to fill in the amount that exceeds the free 10 gas. Fee list is here: https://docs.neo.org/docs/en-us/sc/fees.html

Network Fee: The latest charging rules require a certain fee for additional transactions that exceed 1024 bytes. Teemo will automatically add network fees. So this place is 0 by default.

Transaction-attached gas: If you need to transfer gas to the contract you are calling, then fill in the specific amount in this place.

Add parameters: The parameters of the general contract are of the type (string, object[]). So the first parameter added is the string type, and the second is the array type. If your contract is different, choose the appropriate type for the parameter

Let me give a few simple examples

1. If your contract is Main(int a), then the first parameter is Integer, and no parameter two is required.

2. If your contract is Main(int a, int b), then the parameter one is Integer, and the second parameter is also Integer.

The ps: Address type is filled in with “AWKqEmC1HsC4uBDvaoh5JLtQ2rigMdRSwX”, and in NeoRay it will be converted to byte[]. If you do not understand the choice of the corresponding parameters, you can look at the corresponding post:

Calling a contract and test run it: Calling a contract means sending a transaction to the chain, which changes the data on the chain. Test run mean simulating executing contracts without causing changes to the data on the chain.

Next, based on the contract we deployed earlier, try three examples to demonstrate:

The first example is as follows, Fill in “Hello” in parameter 1, the return is “ByteArray” type, and it’s converted to “World” Common conversion tools: https://peterlinx.github.io/DataTransformationTools/

The second example is as follows, Fill in” return” in the parameter1. Fill in the number 2 for the first digit of the array in parameter 2.

The third example is as follows. Fill in “add” in parameter 1.

Next, we use the parameters of the third example to send the call transaction. The Teemo wallet will pop up a box to request the signature, and wait for a while after the transaction is sent.

0x06 Contract debugging

After a transaction to invoke the contract is confirmed, you can click the contract debugging button to debug the contract. This function is mainly to observe the contract execution process to find where the contract goes wrong when the execution result of the contract is not in line with expectations.

It is important to note that you must choose the correct contract you want to debug. Because the transaction list only shows transactions that the current wallet address calls this contract.

If a transaction is confirmed on the chain, but the corresponding transaction is not displayed on this page, please wait a few seconds or switch the function module and try not to refresh the page.

After selecting a transaction, you can debug it. The following figure shows the instruction process executed by this call. You can observe the execution of the contract through the up and down buttons on the keyboard. You can get the return value of this transaction and the notification of the contract thrown by notify. When necessary, you can debug the contract by throwing a notification, which is similar to the way to log when debugging. The data stored in the calculation stack and the temporary stack can be observed in the lower right corner of CalcStack&AltStack.

Through the instructions executed on the left and the contract code on the right, you can observe which line of code the contract execution has reported errors, or which process is wrong, which is convenient for developers to debug.

The support function module has some NEL website navigation, as well as the function to request gas.

Afterword

NeoRay2.0 brought us some pleasant surprise. Since I don’t use python, I didn’t experience the python process. But in terms of the process of the contract written by C#, it is still great. Debugging and calls are very convenient. At the same time, I was also amazed by the extension wallet Teemo. It’s kind of the equivalent of MetaMask on NEO. It has the potential to become an extension wallet widely used on NEO.

Finally, I hope that NEL will do better and better, and introduce more tools that are convenient for our developers.