A Guide to Corda and CorDapps Development

COVEXCOIN
5 min readJul 2, 2018

--

Contracts, transactions, and their records are among the essential structures in today’s economic, legal and political systems. They help to protect assets and set organizational boundaries. They help to establish, validate identities and chronicle life events. They manage interactions between organizations, countries, individuals and even communities.

They steer both decision-making and social action. And yet these crucial tools and the bureaucracies created to manage them haven’t been kept up-to-date with the economy’s digital revolution. Contracts and transactions are like rush-hour gridlocks trapping a Formula 1 race car.

The unveiling of Blockchain — a Distributed Ledger Technology (DLT) behind a ground-breaking Bitcoin cryptocurrency — in 2009 promised to solve this hurdle. As an open, distributed ledger technology, Blockchain can record transactions between two parties in an efficient, verifiable and immutable manner.

Besides, the can also be coded to trigger transactions automatically. Since Blockchain is decentralized, intermediaries such as bankers, government agencies brokers and lawyers are longer necessary. Blockchain replaces these intermediaries with verifiable, transparent cryptographic computations.

The unveiling of Ethereum in 2015 created a world where any sectorial problem can be embedded in a smart code and stored in a transparent, shared ledger where transactions are protected from tampering, deletion and even revision. Even though the financial industry has long been viewed as stodgy and mired in the industrial-era culture, it was one of the first sectors to begin experimenting with Blockchain.

In an effort to process contracts and transactions faster, cheaper and more efficient, banks are increasingly leveraging the Blockchain technology. However, there are considerable potentials to enhance the cost and efficiency in financial institutions which the underlying Blockchain technologies such as Bitcoin and Ethereum have failed to address.

So, what is Corda?

Corda is a distributed ledger implemented by R3 — a New York-based distributed database technology company with a consortium of over 20 firms. The Platform was designed to help integrate disparate systems into a single global distributed ledger in the banking industry. It has been conceived and developed from the ground up to allow legal contracts and shared data to be controlled and synchronized between mutually untrusting entities in any sector.

Essentially, all the participants in any Blockchain ecosystem are mutually distrusting nodes. However, when applied in such an ecosystem, Corda allows a single global database — the source of truth — to be maintained. Such a database can record the status of obligations and deals between institutions and people in a transparent, verifiable and secure manner.

Corda can eliminate much of the time-consuming effort required to validate transactions which are currently expected to maintain disparate ledgers synchronized with each other. Also, Corda can enhance greater levels of code sharing than presently used in the financial sector and help to minimize the cost of financial services for every party.

Requirements for programming CorDapps

The distributed applications that run on the Corda Platform are called CorDapps (Corda Distributed Applications). The primary objective of any CorDapp is to allow participants to reach an agreement about updates to the globally distributed ledger. CorDapps achieve this objective by defining flows that Corda node owners must invoke via RPCs (Remote Procedure Calls).

Here are primary elements of a CorDapp:

· States: States define the facts over which any agreement will be reached;

· Contracts: Contracts define what constitutes a valid global ledger update;

· Services: Services provide long-lived utilities within the nodes; and

· Serialization whitelists: They restrict what types that your node will receive off the wire

The core of any contract in Corda is an executable program that authenticates changes to state objects in transactions. The state objects are simply data held on the globally distributed ledger and represents the current state of an instance of a smart contract. They can be used as inputs and outputs of the Corda transactions.

To implement a CorDapp, you need to have the following requirements:

· At least an 8 GB RAM PC;

· Elementary knowledge of Java and Kotlin;

· An elementary understanding of web development tools such as HTML, CSS, and JavaScript;

· Knowledge of creating web services using Java or Kotlin, importing and using the Jar inside projects; and

· An understanding of RPC protocols.

Steps involved to implement CorDapp

Here are main steps that you must follow when implementing a CorDapp:

#1: Set up the Blockchain nodes

To create a CorDapp, you’ll need a Corda template. At present, there are 2 variants of Corda template:

· Java; and

· Kotlin

These templates are available from https://github.com/corda. After setting up the Corda template, you’ll need to setup the network with a number of participants (nodes) by configuring the XML file.

#2: Write the state

A state is just a simple data structure written in Java language but having key-value pairs. In Corda, you must define the state that you’ll share with the multiple parties.

#3: Write the smart contract

The smart contract is the code that will create, modify, and remove the state. If you understand Java and Kotlin languages, you’ll not have any problem at this stage. The smart contract that you’ll create is just a class that implements the Contract interface. The heart of any Corda contract is the verify function.

The verify function determines whether a particular transaction is valid or not. Here is an example of verify function developed from scratch:

KotlinJava

class CommercialTransaction : Contract {

override fun verify(tx: LedgerTransaction) {

TODO()

}

}

In the above example, CommercialTransaction is the name of the contract. Notice how the verify function has been used.

#4: Write the flows

There is no way that you can invoke smart contracts directly in Corda. Therefore, you must write a flow which specifies the entire life cycle of state changes by invoking the smart contract that is consistent and related the current state. Writing a flow will also help you to get signatures from other participants who are involved in this state changes.

To write a flow, you’ll need to follow the steps below:

· Get the changed state with the new value;

· Get the participants involved in the transaction;

· Get the signature by the invoking the nodes;

· Create a transaction and send to other nodes to get signed; and

· Receive the signed transaction and send it to the notary for approval

#5: Create a connection to the CorDapp

There are 2 ways you can go about creating a connection to the CorDapp:

· Write the API’s directly inside the Blockchain project: In this case, the API will receive the corresponding arguments and invoke the required flows to execute on Corda; and

· Get the Jar for nodes for the program that you have selected such as Kotlin-jar/Java-jar in the build directory of your project. You can then import the Jar in any Java project and write the API to establish a connection via RPCs from the middleware.

By CoVEX Team

--

--