Summary: The inline assembly language embedded in solidity, described above, can also be used alone. In fact, it is an intermediate language that is intended to be used as a compiler. In this paper, we will introduce the development specification and development process of solidity language in the process of developing intelligent contract.
Solidity is an intermediate language for compilers. Developing smart contracts requires adherence to the appropriate development specifications and development processes.
Development specifications
Naming conventions
Directories and files
- The directory uses lowercase, do not use special symbols;
- The library file and the contract file are unified with. Sol as the suffix;
- The contract file name remains the same as the contract name;
- The file name is named after the Hump (capitalized);
Contract, library file naming
- The name of the contract is named after the Hump (first character capitalization), for example: Usermanager, ActionManager;
- The name of the method uses the Hump method (the first letter lowercase), for example: GetNumber;
- The name of the property uses the Hump method (lowercase), for example: UserName;
- A function or method that starts with a double underscore is called as an internal contract method;
- The contract library name prefix lib+ structure names, such as: Libuser, libaction;
Constants and configurations
- Constants are named with uppercase letters and underscores, such as App_path;
- Configuration parameters are named with lowercase letters and underscores, such as url_route_on and Url_convert;
Directory structure|-app(truffle服务目录)|-contracts(合约目录) | └─interfaces(抽象合约目录) | | └─library(结构解析库目录) | | └─sysbase(公共合约目录) | |-OwnerNamed.sol(基础合约,所有用户业务合约,必须继承此基础合约) | └─BaseModule.sol | | └─utillib(工具库目录) | |-LibDB.sol| |-LibDecode.sol| |-LibInt.sol| |-LibJson.sol| |-LibLog.sol| |-LibNIZK.sol| |-LibNizkParam.sol| |-LibPaillier.sol| |-LibStack.sol| |-LibString.sol| └─Strings.sol| |-migrations(truffle发布配置目录)|-test(测试脚本目录)|-truffle.jsCopy
In general development, the functionality of contract files is categorized by using a catalog, which describes the following features:
- Contracts Truffle Standard working directory of the contract directory, the contract is stored in this directory, such as: Usermanager.sol;
- Interfaces deposit abstract contracts, such as: Iconsumermanager.sol;
- The library holds the structure database file of struct;
- Sysbase stores the directory of public contracts, for example: Ownernamed.sol;
- Utillib Storage Tool Library, such as: Libstring.sol, Liblog.sol;
Development process
- Contract Interface Definition
According to good programming habits, before writing the business method, first define the interface and deliver it to the caller.
- Data structure definition
In a user-defined contract interface, if there is more complex input/output data, it is necessary to define some data structures in advance, and provide some common methods of manipulating these data structures (mainly, some methods of serializing JSON strings).
- Business Contract Preparation
Implement the Contract interface definition and implement the user's business logic. In the constructor of the business contract, the business contract needs to be registered in the module contract.
If users just want to write a business contract, do the study, test, you can register the business contract in the "Juzix.io.debugModule" the special name of the module contract, then the user can not need to write a module contract, in the juice client IDE directly invoke the business contract method.
- Module Contract Writing
Write the module contract, which is the requirement of juice open service platform to manage user's Dapp application and business contract. In the constructor of the module contract, you need to register the module contract with the chain and describe in the constructor all the business contracts that the module contract will use.
After the user has written the module contract and deployed to the juice blockchain, the module name will be displayed in the "My apps" of the juice Open service platform, and clicking on "My Apps" app will jump to the user's open Dapp app. How to set the app's Jump URL, reference module contract writing.
- Compiling the deployment, testing
Through the juice client, or the online IDE, you can compile, deploy, and test user contracts.
Content reference: Https://open.juzix.net/doc
Smart Contract Development Tutorial Video: Introduction to smart contracts for blockchain series video courses
Smart contracts from beginner to proficient: solidity language development specification and development process