IBAX Development Tutorial
Getting Started Guide
Deployment
Advanced Guide
We will deploy smart contracts on the IBAX blockchain via the command line tool (opens new window), and learn how to invoke smart contracts.
As our first smart contract, we deployed it to local test network How to deploy a local network you can refer to Network Deployment ,
so you can deploy and run it as you like without any overhead.
Create application
Call the contract @1NewApplication to create the application, which has an application name parameter and a modify permission parameter
The following is explained by line:
- Line 1, start command line terminal
- Line 5, call the contract @1NewApplication to create an application with the application name
testapp
and the application modification permission @1DeveloperCondition
with developer permission - Row 8, the block id generated by the transaction
- Line 9, the block hash generated by the transaction
- Line 10, if the transaction execution fails (0: no penalty 1: penalty)
- On line 11, if the transaction execution fails, an error text message is returned, and if the block id is returned, the err field is the id of the application
Of course if you want to see what fields and field types are available in this contract, you can call the getContractInfo
method, which will return the contract information as follows:
The fields
field is the parameters of the contract, including the name of the parameter name
, type
, optional
,
Name
and Conditions
are required, VotingId
is optional, refer to contract/name API method
Writing contracts
We use Needle to write a smart contract that
We implement a simple addition operation, the source code of the contract is as follows, we save the contract as SumMath.sim
The following is explained by line:
- In line 1, we define a contract with the name SumMath
- Line 2, Data Section
- In lines 3-4, we define two input 64-bit integer-type parameters
A B
- Line 6, Conditional Section
- Line 9, Operations Section We define a variable sum to receive the result of A+B.
Assign the value of sum to $result, as the result of the contract. Of course it is possible to assign the value of A+B to $result directly, but it can be shown as an example.
Create Contract
There are two ways to create a contract, the first of which is:
In the first step we write a contract parameter file in json format:
where ApplicationId
is the application id, Value
is the contract source code, need to escape special characters, Conditions
is the contract modification rights
We named it SumMathParams.json
The second step calls to create a contract @1NewContract
Second method:
The saved contract source file is passed directly into the contract parameters in the parameter format paramsName
+ -
+ "file",paramsName-file
as follows:
The following is explained by line:
- Line 1: Call the contract @1NewContract to create the contract, -f uses the file to import the contract parameters
- Row 3, the block id generated by the transaction
- Line 4, the block hash generated by the transaction
- Line 5, if the transaction execution fails (0: no penalty 1: penalty)
- Line 6, if the transaction execution fails, an error text message is returned, and if the block id is returned, the err field is the id of the contract
Let's try calling the contract we just deployed
The call is completed and the result is as expected, as explained below by line:
- The first line calls the contract, here we deploy the contract to the ecosystem with ecosystem id 5, of course, if the current ecosystem id is 5, in the same ecosystem, you can also call
callContract SumMath {"A":1, "B":2}
in this way - Line 3, the block id generated by the transaction
- Line 4, the block hash generated by the transaction
- Line 5, if the transaction execution fails (0: no penalty 1: penalty)
- Line 6, if the transaction execution fails, an error text message is returned, and if the block id is returned, the err field is the result of the contract, which is the value of
$result
In this tutorial, you will learn how to:
In order to understand more clearly how the IBAX ecosystem and applications are like and what they do, it is preferred that we understand where the ecosystem and applications should belong, and we can understand better with a simple mind map:
It can be seen that IBAX networks can have many Ecosystems.
Each ecosystem can have multiple applications.
Each application has contract.
Tables.
Ecology has ecosystem parameters, application has application parameters
Step 1 Create Ecosystem
We start by creating an ecosystem using the command line tool (opens new window), calling the contract @1NewEcosystem.
If you want to change the ecosystem name, you can call the @1EditEcosystemName
contract.
The following is explained by line:
- Line 1, which starts the command line console program
- Line 5, call the contract
@1NewEcosystem
to create an ecosystem with the name test ecosystem - Line 8, the block id generated by the transaction
- Line 9, the block hash generated by the transaction
- Line 10, if the transaction execution fails (0: no penalty 1: penalty)
- Line 11, if the transaction execution fails, an error text message is returned, and if the block id is returned, the err field is the id of the ecosystem as
18
Then we configure the command tool config.yml
, set ecosystem
to the created ecid 18
and restart the command line console program
Step 2 Create Application
Call the contract @1NewApplication
to create the application, which has an application name parameter and a modify Permission Parameter
If you need to modify the application permissions, you can call the EditApplication
contract
The following is explained by line:
- Line 1, call the contract @1NewApplication to create an application, the application name is
GradesRecorder
, the application modification permission is developer permission @1DeveloperCondition
- Line 4, the block id generated by the transaction
- Line 5, the block hash generated by the transaction
- Line 6, if the transaction execution fails (0: no penalty 1: penalty)
- Line 7, if the transaction execution fails, an error text message is returned, and if the block id is returned, the err field the id of the application is
47
Let's write a simple example of an application that keeps track of students' grades.
The data table fields include student information, grade grade
, class
class
, subject grades mathematics,physics,literature
, and Composite score overall_score
, rating score
, creation timestamp (ms) created_at
Step 3 Create Table
In the first step we write a contract parameter file in json format:
where ApplicationId
is the application id,Name
is the name of the created data table test_teble
.
ColumnsArr
is an array of data table fields, TypesArr
is the type of data table fields, including 9 types varchar
,character
,json
,number
,datetime
,double
,money
,text
,bytea
, the field name and the field type are one-to-one correspondence.
InsertPerm
for data table new entry permission, UpdatePerm
for data table update entry permission, ReadPerm
for data table data read permission, NewColumnPerm
for new data table field permission
Referring to Permission Control , hereContractConditions(\"MainCondition\")
is available for the current ecosystem creator.
We name it createTable.json, and then call the contract to create the data table @1NewTableJoint
Modify data table field permissions
We can modify the data table field permissions, data table field permissions include read permissions and update permissions, where read permissions,
in the contract using DBFind.Columns
filter fields or interfaces such as list query,
if there is no permission, it will report a permission error.
The update permission is the permission to update the data table fields.
We set the student
field read and update permissions to false
, but of course it can be set to be operable by some contract.
Call the @1EditColumn
contract to modify the data table field permissions
We can create several application parametersgrade_best_type
,grade_type_a+
,grade_type_a
,grade_type_b+
,grade_type_b
,grade_type_c
, grade rating type
Step 4 Create Application Parameters
Call the contract @1NewAppParam
to create the application parameters, if you want to modify the application parameters you can call the contract @1EditAppParam
.
where grade_best_type
is the best rating type.
grade_type_a+
is the condition triggered by the rating A+
, when the score is greater than or equal to 90 and less than 101, the rating isA+
, other parameters are similar
Step 5 Create Contract Deploy Contract
We create a contract to record the student's grade information and final rating for each subject, and enter the student's grade class and grade for each subject when entering the information.
Based on the input scores of each subject, the average calculation is done to get the overall score overallScore
and the final ratingscore
.
When the contract is called, it will create a record to the data table we just created grade_info
First we write a contract and name it NewRecord.sim
The following is explained by line:
- Line 2, data section defines the input parameters
Student
student name, Grade
grade, Class
class, Mathematics
math score, Physics
Physics score,Literature
Literature score - Line 10, the getScore function, produces a composite score and final rating based on each subject's score
- Line 30, safeJsonDecode function, json decode the string and convert to map
- Line 38, conditional section
- Line 39, operation section
As you can see, when the contract is called, it first goes through the conditional part, verifying that the contract input parameters are valid, such as whether the student name if Size($Student) == 0 {
is empty (line 39), and if it is, then an error message is returned
"Student Can not be empty"
(line 30), after all input parameters have been verified, on line 61, use DBFind to retrieve the information from the database for the application with the ecid 18
and the application name GradesRecorder
and the application information with deleted=0
is not deleted.
Lines 69-74, use AppParam to retrieve the application parameters, e.g. $gradeBestType = AppParam(app_id, "grade_best_type", $ eId)
(line 69).
If the application parameter is stored in json format, such as grade_type_a
, you can refer to $gradeTypeABest = safeJsonDecode(AppParam(app_id, "grade_type_a+", $eId))
, which will get the application parameter by safeJsonDecode function to map format
Then execute to the operation part, call the getScore function to get the resulting composite score and final rating (line 10), use map to store, line 79, define a map to store student achievement information, and
DBInsert Insert data to data table@18grade_info
.
There are two ways to create a contract, the first of which is:
First we write a contract parameter file in json format:
Where ApplicationId
is the application id, which needs to be escaped for special characters, and Conditions
is the contract modification permission.
Value
contract source code, which we save as NewRecordParams.json
:
After writing the contract, we need to deploy the contract by calling CreateContract@1NewContract
The following is explained by line:
- Line 1: call contract
@1NewContract
to create the contract, -f uses the file to import the just created file NewRecord.json
as the contract parameter - Line 3, the block id generated by the transaction
- Line 4, the block hash generated by the transaction
- Line 5, if the transaction execution fails (0: no penalty 1: penalty)
- Line 6, if the transaction execution fails, an error text message is returned, and if the block id is returned, the err field the id of the contract is
348
Second method:
The saved contract source file is passed directly into the contract parameters in the parameter format paramsName
+ -
+ "file",paramsName-file
as follows:
Let's try to call the contract we just created
The call is complete, and then we check to see if the data table has saved a record
You can see that there is already a record in the data table, student
tom with an overall rating of 56 and a grade of C
The above example is only for study and research purposes, you need to change the relevant parameters according to the actual situation, such as the data table write permission, contract modification permission, etc.
For example, if we want to specify that only one person can call this new record contract and no one else can call it, we can set an ecosystem parameter new_record_account
Step 6 Create Ecosystem Parameters
Calling the contract @1NewParameter
will create the eco-parameter
new_record_account
in the @1parameters
table, if you need to modify the eco-parameter you can call @1EditParameter
.
We create an ecosystem parameter new_record_account
, set the value to keyId 6667782293976713160
, modify the permission toContractConditions("MainCondition")
which means the current ecosystem creator can modify
When the transaction is executed successfully, the ecosystem parameter id of the "err" field is 273
.
Step 7 add localization
You can call the @1NewLangJoint
contract to create the localization parameteraccount_not_access
, which will create the parameter in the@1languages
table, and you can modify the localization parameter via@1EditLangJoint
.
Step 8 Modify the contract
Next, we need to modify the conditions
section of the contract source code by adding the following code to conditions
Call to modify the contract @1EditContract, where Id
is the contract id, Value
: is the contract source code
Step 9 Modify data table permissions
Here we need to change the insert permission of the data table, the original permission ContractConditions("MainCondition")
for the ecreator, and the contract setting new_record_account
is not the ecreator.
So just change ContractConditions("MainCondition")
to specify that the contract can operate on ContractAccess("@18NewRecord")
.
Call the contract @1EditTable
to modify the data table permissions
Then call the contract you just modified and create a new record
You can see that the localization parameter we just set,account_not_access
, is working
We found that the permission error is reported, the current user does not have permission to operate, we switch to the account with keyId 6667782293976713160
, we can get the current user's information through the command line toolaccount info
Set up the command line tool config.yml and switch to the account with keyId 6667782293976713160
After the setup is complete, call the contract again
The call completes, querying the data table via getList @18grade_info
, and the result is as expected
We hope this article has helped you learn more about how the IBAX network works and how to write clear and secure Needle
code.
In this tutorial, you will learn how to:
Before starting this tutorial, you need to have an application of your own and know the concept of ecosystem and application, you can refer to Getting Started Guide
We will import the application on the IBAX blockchain via the command line tool (opens new window). Exporting an application
Export Application
Call account info
to query the current account information, here the login ecid is 9
, call getList
command to query the current ecid which applications
We can see that the current ecosystem has 6 applications, we use theexport
command to export the application with id
of 36
The -f parameter here saves the exported application to the data.json
file in the current directory.
If there is no -f parameter, the application data will be output in the command terminal
The export
command encapsulates the steps to export an application. You can use the above command to export an application, or use the following steps, as follows:
Calling the contract @1ExportNewApp
to export a new application will generate a record in the 1_buffer_data
table for the exported application
Call the contract @1Export
to export the application, find the selected application in the 1_buffer_data
table, and export all application resources to the generated json string.
The generated json string will be written to the 1_binaries
table of the current ecosystem
Query the data in the 1_binaries
table with the getList
command
Get the binary id and hash
Call the binaryVerify
command to export the binary file
Import Application
Use the import
command to import an application, with the -f
parameter to specify the application file to be imported
The import
command encapsulates the steps to import an application, you can use the above command to import an application
Or use the following steps, which, for ease of study and research, are as follows:
- Step 1
Calling the contract
@1ImportUpload
to import a new application will generate a record in the 1_buffer_data
table for the exported application
@1ImportUpload
The contract parameter Data
is file
type.
Contains the keywords Name
file name (string), MimeType
file type (string), Body
([]byte) file content
You need to base64 encode the application file data and pass it into Body
, you can use the base64Encode
command to base64 encode it
- Step 2
After the call is completed, use the
getList
command to query the data in the 1_buffer_data
table
- Step 3
Assemble the data in value.data->Data into a one-dimensional array, [a,b,c,d].
Then create a contract parameters file
importParams.json
, with the following content:
- Step 4
Call the contract
@1Import
to import the application data
In this tutorial, you will learn how to:
- Apply to join the ecosystem
- Add ecosystem members
- Freezing of accounts
- Role management
- Issuance of Token
- Eco Deduction
- DAO Governance Ecology
Before starting this tutorial, you need to have an application of your own and know the concept of ecosystem and application, you can refer to Getting Started Guide
We will do the ecosystem configuration on the IBAX blockchain via command line tool (opens new window)
Apply to join the ecosystem
We can call the @1MembershipRequest
contract to request to join the ecosystem
The following example:
request to join the ecosystem with ecosystem id 19
, the @1MembershipRequest
contract makes a restriction on calling the ecosystem, only in the base ecosystem can be called
When the application is successful, the target ecosystem manager will receive an application, and only when the application is approved by the ecosystem manager will it be considered as joining the target ecosystem.
Of course, if the target ecosystem is public, you can join the target ecosystem directly
Add ecosystem members
When the ecosystem is just created, the ecosystem member is only the ecosystem creator, when you need to invite other members to join, you need to know the public key of the invited person, and then call the contract @1MembershipAdd
to add members
If the ecosystem is public and allows anyone to join, you can set the ecosystem parameter free_membership
= 1, which is not public by default.
Once set up, you don't need to be approved to join your ecosystem
If you don't set the parameter free_membership
, when other members apply to join your ecosystem, you will receive an application notification.
Call @1MembershipDecide
contract approval application, contract parameters NotificId
is the notification id, 'Accept' is the resolution mark, resolution mark 1
is passed
Freezing of accounts
Call @1DeleteMember
contract to freeze the account, note that this operation cannot be restored
Role management
New role creation
Call @1RolesCreate
contract to create a new role, role name student
, type 2
(1 - Assignable 2 - Elected by vote type 3 - System)
The return result contains the role id 21
Adding Role Members
There are two methods, the first method, the ecosystem member to initiate the application, call the contract @1RolesRequest
request to add as a member of the role, where Rid
is the role id
In the second method, the role manager assigns role members, and the role manager calls the contract @1RolesAssign
to add members to the role
Delete role members
First we see what members a role has, which we can query via getList, as follows:
where the where
condition ecosystem
specifies ecosystem, role->id
specifies the role id, and deleted
: 0 specifies not deleted.
We can see that we have 3 rows, if we want to remove the role with member 1273-2644-xxxx-5846-6598
, that is, the role with id
of 21
.
Administrators can call the contract @1RolesUnassign
to remove role members, as follows
Modify Role Manager
Let's look at the current ecosystem roles
where roles_access
is the administrative role for the current role, which is an array and can have more than one.
We add an administrative role to the role teacher
by calling the @1RolesAccessManager
contract, where the contract parameters Action
administrative operator (clean
, remove
, add
),Rid
the role ID to be managed, ManagerRid
the Rid Manager of the role
Delete Role
We can call the @1RolesDelete
contract to delete roles, where the contract parameters Rid
is the ID of the role to be managed and Ops
is the operator (D
is delete R
is restore)
Issuance of Token
Create Ecology
Create an ecosystem, call @1NewEcosystem
contract
Then we modify the command line tool configuration to log into this newly created ecosystem: "21"
Installing Basic Applications
Call the contract to install the base application, as follows:
Line 1, install the platform application
Line 2, install default role
Line 3-4, install the eco-configuration and token issuance application, where the application id 5,6
can be queried via getList as follows:
Token Issuance
Because it is a new ecosystem, you need to set up the token issuance, call @1TeSettings
contract to specify the roles that can issue tokens
where RoleDeveloper
is the current ecosystem role id, which can be obtained through the @1roles
data table
Token Issuance Call @1NewToken
contract to issue tokens
where the contract parameters Symbol
is the token symbol, Name
is the token name, Amount
is the total amount, and Digits
is the precision.
Token Emission
Destroy tokens
Default token increment and token destruction is allowed, you can set it off by @1TeChange
, where TypeChange
is the type (emission
increment,withdraw
destruction).
Value
is the on/off status (1
on, 2
off), e.g:
Close Additions Note: Cannot be turned on after closing
Turn off destruction, if you want to turn on destruction again, just set Value
to 1
.
Eco Deduction
Before setting up eco-deductions, you need to understand the IBAX fee model, which can be found in the white paper (opens new window).
We first set the eco-wallet address, call the @1EditParameter
contract and modify the eco-parameters
where Id
is the ecowallet ecosystem_wallet
parameter id, which can be queried as follows:
The Value
value is the address of the ecowallet that will be bound, and the contract generates the gas fee, which is paid by that address. The address must have enough tokens in the current ecosystem and needs to be agreed by the bound address before the modification will be successful
Call @1EcoFeeModeManage
contract to set up multi-ecosystem deduction, as follows:
where the contract parameter fields are defined as follows:
FollowFuel
parameter is a multiple of the follow eco1 rate CombustionFlag
whether to turn on ecotrade gas fee combustion, 1- no, 2-yes CombustionPercent
Combustion percentage, only effective when gas fee combustion is turned on, takes values 1 to 100, 0 when not turned on VmCostFlag
VM cost flag, set direct or proxy payment, 1 - direct payment, 2 - proxy payment StorageFlag
storage fee flag, set direct payment or proxy payment, 1 - direct payment, 2 - proxy payment ExpediteFlag
Expedited fee flag, set direct payment or payment on behalf of, 1 - direct payment, 2 - payment on behalf of VmCostConversionRate
Virtual machine cost conversion rate, 2 decimal places, only in effect for proxy payments, greater than zero StorageConversionRate
The storage cost conversion rate, 2 decimal places, only in effect for proxy payments, greater than zero
If you use the above settings, all transaction fees incurred by users invoking contracts within the ecosystem will be paid by the ecosystem wallet of the current ecosystem setup.
All users only need to pay for the gas costs incurred within the ecosystem. Of course you can adjust the cost parameters according to your actual needs
DAO Governance Ecology
Before modifying to DAO governance ecosystem, you need to ensure that the current ecosystem has issued tokens, and after modifying to DAO governance ecosystem, all proposals of the ecosystem will be voted on by the members of the governance committee.
The DAO Governance Board is no longer managed by the eco-developers alone, and the top 50 representatives of the eco-holdings are elected.
Call the @1EditControlMode
contract to change the eco governance mode to DAO governance mode.
where the Value
parameter 1
represents the creator model 2
represents the DAO governance model
We can try to create an application
At this point a DAO governance proposal is generated and voted on by the DAO Governance Board before the application is created. A valid proposal requires a 68% approval rate out of 75% of the votes cast.
The scope of DAO governance includes:
- Add, delete and change applications, contracts, pages, code snippets, tabs, menus, application parameters, data tables and fields
- Modify multilingual
- DAO and creator model switch
- Edit ecosystem parameters
- role, assign remove role members
- Issue additional destruction currency
- Modify the platform parameters
- Modify ecosystem information
- Modification of delayed contracts
- Modify the voting template
Before starting this tutorial, you need to download IBAX Application Packaging Tool (opens new window) , we need to use this tool to package IBAX application.
We need to store the application files according to the following directory structure
As shown below:
The app_params
directory stores the application parameters file, named using the parameter name + file format .csv
, the content of the file is the parameter value.
The contracts
directory holds the contracts, in .sim
file format, and the contents of the file are the contract source code.
The tables
directory holds the application data table structure in json
file format, as follows:
name
is the datatable field name, conditions
is the datatable field permission, and type
is the field type.
In step 1, we generate a config.json file and save it to the airdrop directory with the following contents:
Where name
is the name of the application, conditions
: is the permission to modify the application, and then save it to the airdrop directory.
Step 2, package the application, the following command will generate the application airdrop.json
in the current directory, if you modify the contract or application parameters, you need to repackage the application.
We can import the application via command line tool (opens new window) as follows:
Use the import
command to import an application, with the -f
parameter to specify the application file to be imported
Of course if you have an application, you can also generate the complete directory structure with the following command