Apla Blockchain Platform For Dummies

Arun Mathew Kurian
Apla
Published in
8 min readNov 20, 2018

The Platform

The Apla blockchain platform allows small and medium enterprises to reduce operational costs, can be used to fundraise projects and automate various processes by providing a ledger based ecosystem. Apla offers a growing number of DApps to automate various business activities.

The platform provides ready-to-use, integrated development environment and business management tools for creating applications. Developers will be able to offer white label applications for specific use cases on Apla that can be accessed by enterprises and their customers from any of the ecosystem without having to create a new software solution.

In this article, we will go through installing Apla nodes to building our first app on the platform.

Setting up local nodes using Apla Quickstart

Apla Quickstart is a software package that provides Docker containers of up to five local nodes of Apla platform. Each node has its own backend, database, and UI client. Apla provides a graphical interface, an integrated development environment, and inbuilt applications functionality like a notification system, user roles and rights management. It also allows the developers to develop, test and deploy their DApps easily.

Installation

Make sure that your Docker is running.

Linux/Mac

If you are a Linux/Mac user go to https://github.com/AplaProject/quick-start.

Head to releases, copy the link to the zip file of the latest version.

Open Terminal

Type: wget https://github.com/AplaProject/quick-start/archive/v0.7.1.zip

This will download a file v0.7.1.zip. Extract the file using unzip command. After the file is extracted, change directory to the folder.

To install 3 nodes, enter:

./manage.sh install 3

This will download and install all the required software, that is the docker containers with Apla backends. If the docker is not present the docker will also be installed.

Apla Ecosystem

Apla uses a unified client called Molis which is installed as part of QuickStart. It can be used by ecosystem administrators to manage, and users to interact with the ecosystem. Molis manages the development and testing of contract codes, tables, and access rights

After the installation, three client instances are launched for each user. The first client instance will have the private key of the founder of the network. This account is privileged with the Admin role. The default password is default.

Apla App Structure

An Apla app can be considered as a combination of three resources. They are contracts, tables, and user interfaces. All operations with contracts, tables, and interfaces are stored in the blockchain. A transaction is created for an operation. This transaction is then validated and executed in a virtual machine on all blockchain network nodes. Thus the state of resources is the same for all network nodes.

Tables

Tables store the information used by contracts and user interfaces. They are the same as regular database tables. The actions query, update and insert are performed with three Simvolio language functions: DBFind, DBInsert, and DBUpdate.

Contracts

Smart contracts or contracts are the only way to perform operations like change or insertion of data in a blockchain. They can take input parameters to validate and perform operations just like normal functions. In Apla, ecosystems contracts are written in a Turing-complete language Simvolio. A contract written in Simvolio will have the following structure:

contract MyContract {
data {
FromId int
ToId int
Amount money
}
conditions {

}
action {
}
}

Contracts are declared with the contract keyword, followed by the new contract name. The contract’s body must be enclosed in curly brackets. Every contract consists of three sections:

  1. data — declares the input data (names and types of variables);
  2. conditions — verifies the validity of inputted data and performs any other checks;
  3. action — includes the actions performed by the contract.

Web User Interfaces

User interfaces are pages and menus that will be displayed to users in Molis. The interfaces are written in Protypo language.

App Development Using Apla Quickstart

Now we have done the initial setup, we can now build our DApp. In this tutorial, we will be creating a DApp that takes two values — name and age from a user — and displays it.

Creating a new app

  1. Go to the Admin tab.
  2. From the list on the left, select Application.

3. In the Applications view, select Create.

4. Specify the name of your app in the Name field.

5. In the Change conditions specify true. Another option is to specify ContractConditions(“MainCondition”).

ContractConditions(“MainCondition”) will forbid application changes to anyone except the founder.

6. Your app will appear in the list of apps. Click select to make it active.

Table Design

Our app needs a table to store data. This can be created as follows.

  1. On the Admin tab, select Resources > Tables.

2. Click Create.

Create table view will be displayed.

3. Specify a name for your table in the Name field and add the columns.

This tutorial uses the name DemoTable for the table.

Our table has fields name and age to save user input. It also has the fields author and timestamp to store an identifier of the author’s account and the time of create.

4. Click on save.

That’s it, our table is now created.

Creating the Contract

Next, we need to write the most important part of our app: the contract.

To create a new contract

1. On the Admin tab, select Resources > Contracts. This will display all the contracts in the app.

2. Create a new contract by clicking on Create. This will open a new code template.

Now we can create our smart contract.

contract DemoAppContract {
data {
Name string
Age int
}
conditions {
if Size($Name) == 0 {
error “Name is empty”
}
}
action {
DBInsert(“demotable”, “name, age, author, timestamp”, $Name, $Age, $key_id, $time)
}
}

As you can see the data part of the contract declares two variables Name and Age. The condition part contains a single condition that the Name must not be empty and the action part inserts these values into the database along with author key and time.

3. Click Save and Execute

A window will appear that prompts us to enter the parameters. After entering them click Exec.

We can see in the database that an entry is created with the given values.

Building an Interactive UI

The last part of our app is the interactive UI.

  1. Navigate to Admin > Resources > Pages.
  2. Click Create. This will open a visual editor

The visual editor can have two views: designers view and developers view. For brevity, we will create a minimal template using the developer’s view in protypo.

DBFind(Name: demotable, Source: src_table).Columns(Columns: “name,age,author,timestamp”).Order(timestamp)Div(Class: panel panel-primary) {
Div(Class: panel-heading, Body: Table block)
Table(Columns: “AUTHOR=author,TIME=timestamp,Name=name,Age=age”, Source: src_table)
Div(Class: panel-footer text-right) {
Button(Class: btn btn-primary, Contract: ContractName, Body: More)
}
}

We can see that in the code the data is fetched from DB using DBFind and this data is displayed in a table.

3. Save the File as DemoPage.

Now if we open this page from Pages menu, we can see the records saved in the database

We must give a form for the user to input new data from this UI.

Div(Class: panel panel-primary) {
Form() {
Input(Name: name_input, Class: form-control, Type: text, Placeholder: “Write your name”, )
Input(Name: age_input, Class: form-control, Type: text, Placeholder: “Write your age”, )
Button(Class: btn btn-primary, Body: Send, Contract: DemoAppContract, Params: “Name=Val(name_input),Age=Val(age_input)”)
}
}

Now we can add new entries to the database from this UI itself.

Before we wrap up we need to do one more thing. We need to link this page to a new menu so that it is displayed on the Home tab. To do that:

  1. Navigate to Admin > Menu.
  2. Edit the default menu. A template will open.
  3. Add the following line of code to the end of the template.
MenuItem(Title:DemoApp, Page:DemoPage, Icon:Icon:”fa icon-people”)

4. Click Save.

Now if we go to the Home Page we can see our new menu DemoApp at the end of the default menu.

That’s it: our app is now ready.

Wrapping Up

Now our app can be deployed to the public network using the platform’s application import and export functions.

This is a very basic example that displays the potential of the platform. As far as DApp development goes, the Apla platform is simply great. The best thing about Apla is that through the introduction of a simple smart contract editor environment and a JavaScript-ish language it will attract more people to DApp development.

Explore Apla and build something awesome!

Arun is a computer engineer by profession and develops apps in Ruby on Rails. He is interested in learning new things especially about technologies like blockchain and machine learning. In his free time, he loves to read books and watch movies.

Blockchain Business Review from Apla provides high-quality educational material from the world of blockchain to inform the business community of the competitive advantage that can be gained by integrating distributed ledger data storage within organizations. Our mission is to promote knowledge about blockchain and its uses in both the private and public sector and demonstrate the value of blockchain integration.

--

--