Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the process of developing NEO smart contracts?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you the relevant knowledge of what is the process of developing an intelligent contract for NEO. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

Two-step flow method

Traditionally, NEO intelligent contract development has a two-step development process: coding and testing. This official tutorial provides detailed information about this workflow.

During the coding phase, NEO officially supports C # (example). We can also use Java and Python to develop smart contracts. You can easily find tutorials and sample code pages on Google and YouTube to learn how to write NEO smart contracts.

We rely on the test network for testing. As shown in the figure above, we have many options for the test network.

Public test network

The most common method is to use a public test network. NEO Smart economy, CoZ and NEL maintain three major public test networks respectively. Alex Guba's tutorial details how to synchronize blocks and apply for GAS before testing on NEO and CoZ test networks, but NEL's test network is more friendly to Chinese developers who support localization.

In most cases, you can run RPC calls through NEO API (full reference) to interact with the blockchain. Partial APIs is only available if you are running a NEO.CLI node with an open wallet. But if NEO.Scan gives the test network permission, you can invoke a similar service without running the node. For example, API getBalance needs a running node, but you can use the get_balance interface provided by Neo-Scan to get similar functionality. I set up a Postman collection to help test these remote calls. You can use it simply by changing the value of the test network (or Neo-Scan).

NeoCompile Eco has a new special public testing network, which inspired us to move to a four-step workflow. We will discuss it in detail in the next section.

Private test network

Another good way is to set up your own private testing network. Compared with the public test network, the advantage of the private test network is that you can gain complete control. The first reason to use a private test network is that it is really useful and inspiring, because it creates the illusion that millions of NEO and GAS are in your wallet. At the same time, compared with the public test network, we do not need to worry about chain regeneration, connection failure, or network congestion caused by other developer errors.

The NEO website provides a step-by-step guide to setting up a private network on a CVM. But after looking at my Azure bill, I don't recommend it unless you have to share chain data with others. Neo-privatenet-docker is ideal for building a private test network on a local computer, while saving you a lot of time to configure and execute instructions. If you run it on your laptop, it can also help you maintain your body temperature in winter in Canada.

The limitations of the two-step process method

This two-step workflow approach has matured and has been adopted by most existing projects. However, compared with traditional software projects, it still has some limitations. The main point is that debugging is very expensive, and the best option to monitor the runtime values of variables is to use run-time notifications, as shown in the following code snippet:

Byte [] ba0 = CallSomeFunction (); byte [] ba1 = CallAnotherFunction (); / / Print out the value of ba0 and ba1 to ApplicationhLogRuntime.Notify (ba0, ba1)

We need to recompile the project using neon, make sure there is enough GAS and redeploy, compose the appropriate parameters with the correct format, then call it and wait 20-30 seconds for the next block to appear, call API getapplicationlog to get the log in JSON format, and print the contents of the response in pretty format format to find the log value (see the highlighted section in the following example). Log values are usually represented as byte arrays, so we need to convert them to strings or large integer types. A total of seven steps.

[{"jsonrpc": "2.0,2.0,5," result ": {" txid ":" 0x7e3f08a8af4290693184b413ba1d58bede8462cb565baba8ffcc380bf947e317 "," executions ": [{" trigger ":" Application "," contract ":" 0x32682404d4313ecf80b70e1323ccf908a80fdfc0 "," vmstate ":" HALT, BREAK "," gas_consumed ":" 0.039 " "stack": [], "notifications": [{"contract": "0xaeccdcf6d7ecf827e7e6baec3c233eca08c27ee3", "state": {"type": "Array", "value": [{"type": "ByteArray" "value": "010203"}, {"type": "ByteArray", "value": "04090d"}]

There are chapters on unit testing in the official documentation, but the examples still require pre-compilation and / or deployment of .avm files.

When we were developing CarryBattle, a NEO-based blockchain game, my team norchain.io felt this limitation strongly. With the help of the community, we began to try a four-stage workflow, which greatly improved the efficiency of development.

Four-step flow method

The four stages of this workflow are editing, debugging, private testing, and Beta testing. The main idea is:

Some new tools are used to split the coding phase into coding phase and debugging phase. During the debugging phase, we skip or run as many local test cases as we can, just like traditional software projects, without interacting with the block chain.

The testing phase is divided into private testing and Beta testing, using privateNet / NeoCompiler Eco for private testing and public testing network for beta testing respectively. Using this approach, we ensure maximum flexibility and compatibility at a minimum cost.

Compared to the following table, we can see the advantages of Neo-Debugger and Neunity.Adapter accordingly. In our experience, Neo-Debugger is more suitable for small-scale projects because it does not consume GAS, while Neunity.Adapter is more suitable for larger or more complex projects because it better supports TDD, multi-classes, breakpoints, variable tracking, and so on.

Neunity's design practices the project methodology of large-scale software (I mean the scale of the system logic, which does not mean that a single call has to be complex or expensive). The use of the adapter layer is an important step in bridging the gap between .net developers and NEO developers. At the same time, Neunity also provides a Neunity.Tools layer, which has a flexible serialization tool (NuSD), HTTP-like communication protocol (NuTP), URI-like storage manager (NuIO), and so on. We hope to help the landing of more NEO blockchain Dapps.

Private testing

After completing the logic through the iterative coding and debugging phase, we can move to the private test phase and start interacting with the block chain. We recommend using a private test network or NeoCompiler Eco for private testing because their environment is simple and easy to interact and manage.

The NeoCompiler Eco public test network developed by NeoResearch is new and special. It does not need to use GAS, but also provides a complete set of Web-based GUI tools, including compiling, importing OpCode, deploying, calling, trading, conversion, etc. NeoResearch recently integrated gitter.im for live chat to better communicate with developers. Igor has a good tutorial to introduce its basic functions.

Another advantage of this test network is that the chunk generation interval is 5-7 seconds, almost five times faster than normal. It shortens the wait time, and there are few calls conflicts among developers in the same block, which makes testing almost as simple as a private test network. This is why we recommend it as a private testing option.

Beta test

If we successfully complete all the functional tests in the private test phase, we can move on to the final phase, after which we can launch Dapp. The public test network is the most suitable place for Beta testing because it is similar to the main network environment. Another advantage is that you can also invite your friends to help with the test. Your smart contract should also be able to calmly face challenges from parallel calls, potential blind spots, or invalid input.

These are all the contents of the article "what is the process of developing NEO Smart contracts". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report