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 接入安全指南
ABI File
Using JavaScript to develop blockchain smart contract is supported in FIBOS. In the previous chapter Quick Start, in the JS smart contract that we wrote, there is another contract ABI file beside the contract code JS file. We didn’t make it clear at that time, so here we will go through the details of the ABI file.
What is ABI
The full name of ABI is Application Binary Interface. It is a Interface file, which describes the data tracsfer format between smart contract and the upper applications. ABI file format is similar to JSON which has a good readablity. It is good for connection between smart contract engineers and upper applications engineers.
For JavaScript contract, ABI file is needed to define actions
and tables
.
Smart contract ABI files are composed of 5 parts:
1 | { |
We will go through the development method of FIBOS smart contract ABI by the sequence of actions
-> tables
-> structs
-> types
ABI Development
actions
Part of the usage of action is to define the actions that can be called by the smart contract as shown below:
1 | "actions": [{ |
Each name
is the action name, while type
is used to find data structure in structs
, and ricardian_contract
is Ricardian Contract.
Ricardian Contract is a special Structured text, mainly used to declear intentions of both parties in trading. In FIBOS, each action you send can be added with contract. This type of contract is special, it has a fixed format that can be read by both programs and human beings. This is what we called the Ricardian Contract.
Attention: Action names follow the naming rules of eos.
Currently, the naming rule: composed of only Numbers 1-5 and lowercase English letters ; The maximum character length is 12.
If any changes are made later, we will modify the document in time.
tables
tables
listed the data tables that need to be build in the smart contract and also the structure name saved in data table.
1 | "tables": [{ |
The codes above built a table named players, the structure type is player, main key is id, type is int64 data table.
structs
There is a correspondence between part of the content of structs
and part of the content of actions
. We just defined an action name at above actions
. We also need to define structs
the incoming parameters for each action.
1 | "structs": [{ |
1 | "structs": [{ |
Through base
field inheritance is equivalent to:
1 | "structs": [{ |
FIBOS system will find the corresponding data structure in structs
by the type
defined by actions
. In fields
of each data structures, name and type of each parameter will listed.
Except that, not only the projects in actions
need to list detailed data structure in structs
, but also the projects in tables
1 | "structs": [{ |
So, in structs
we defined a struct named player. It is used to list data table player including 2 strings: nickname
and age
, the types are my_account_name
andint32
types
types
is used to define data type:
1 | { |
So in this ABI file, we defined a type name named my_account_name
,the type is name
, new_type_name
and type
are keywords, type name
is the data type defined by system.
Conclusion
So, a complete ABI file is now written.
1 | { |
Through this ABI file, we defined an action method, it has 3 strings: id, nickname, age; types are: int64, my_account_name, int32; a data table player main key is id and a Passing parameters of nickname, type is my_account_name and the name is hi.