Guidelines
- Introduction
- Installation
- Quick Start
Guides
- Introductions
- Build local test node
- Smart Contract - ABI Files
- Smart Contract——JS Contract
- Deploy Contracts
- Test Contract
- Develop DApp Client
Smart Contracts
- Contract Introduction
- ABI File
- Database
- Account Authority
- Call In-contract
- Notification
System Contracts
- Resources
- Account
- Permission
Token Contracts
- Transfer
- Token
- Token Exchange
- Contract Sub-Wallet
Node Guide
- Node Introduction
- Add to nodes network
- Node Data Persistence
Access Guide
- FO 接入安全指南
Smart Contract - ABI Files
ABI, called the Application Binary Interface, as the name implies, refers to an interface file which describes the data interchange format between the smart contract and the upper-layer application. The ABI file format is similar to JSON format, and it is highly readable so as to facilitate the work connection between smart contract developers and upper application developers.
For contracts developed by JavaScript, it is required to use ABI files to define the definition of actions and tables.
The Smart Contract ABI file consists of five parts:
1 | { |
version
:refers to the version number of specified ABIstructs
:represents various types of data structuresactions
:states the called action of smart contractstables
:lists the name of the data tables in the smart contracts, and the name of the struct stored in the data tablestypes
:used for customized data
We will illustrate the development method of Smart Contract ABI on FIBOS in the order of structs -> actions -> tables -> types.
Create new contracts
folder,and save the code to contracts/todo.abi
:
structs
There is a one-to-one correspondence relationship between the content of the structs section and the content of the actions section. It is necessary to declare the parameters required to be passed to each action in the structs as following.
1 | "structs": [ |
The FIBOS system will look for the corresponding data structure in the structs section according to the type declared in the actions section. Furthermore, the name and type of each parameter will also be listed in the fields of each data structure.
In addition, the detailed data structure of both items in actions section and items in tables is require to be listed in structs.
1 | "structs": [ |
Thus, we define a struct named todo_index in structs, so as to list the data table of todo_index, including the field id(int64); a struct named todo is used to list the data table of todo, including the field id(int64), text(string), and completed(bool).
actions
The action section is used to declare which action the smart contract can call. In the following code example, the action defines four methods which are adding data, finding data, modifying data, and deleting data.
1 | "actions": [{ |
The name in each item refers to the name of the action, while type is used to find the data structure in structs, and the ricardian_contract is a Ricardian Contract
The Ricardian Contract is a special structured text that is used primarily to clarify the intentions of both parties of the transaction. On FIBOS, contracts can be attached to every action you send. Such a kind of contract is very special and has a fixed format so that it can be read by both programs and humans. This contract is called the Ricardian Contract.
Note: An action is named following the naming rule of EOS.
The current naming rule on naming of action: only consisting of numbers from 1 to 5 and English lowercase letters; the maximum length of characters is 12.
tables
tables lists the names of the data table that needs to be created in the smart contract, and also the name of the structs stored in the data table.
1 | "tables": [{ |
The above codes construct a data table with the name todos, the structure type todo, the primary key name is id, and the primary key type is int64.
types
types are used to customize the type of data:
1 | { |
In this way, in this ABI file, a type with the type name of my_account_name is customized, and the type is determined as “name”. Moreover, “new_type_name” and “type” are the keywords, and the “name” type is a system-defined data type.
ABI file code example
According to the instructions above, we wrote the contract required for this article. The following code is saved as contracts/todo.abi.
1 | { |
Note: Please do not add any annotations to the ABI file, otherwise an error will be reported!
Through the ABI file, we define four actions, including emplacetodo(todo), findtodo(todo_index), updatetodo(todo), and destorytodo(todo_index); the primary key of corresponding structs is todo_index, qualified with three attributes of id(int64), text(string), completed(bool)
The GitHub source code for this article: under the contracts
folder of
https://github.com/fengluo/fibos-todomvc
Next Chapter
👉 【Write JavaScript Smart Contracts】