Corda: The Smart Contract Based Blockchain Project

0
4627

Making reliable transactions over a network is the baseline requirement of most businesses. Blockchain technology enables different parties to transact efficiently and in a verifiable manner. Corda is an open source blockchain project. Its smart contract technology allows businesses to transact safely. This article introduces you to its features.

With the massive increase in the size and nature of services that are provided through the networks, security has emerged as a priority requirement. Even as there are innumerable efforts on to improve transaction safety, the blockchain has captured people’s attention in recent times. By design, the blockchain is resistant to data modification. Primarily, the blockchain consists of a growing list of records termed as blocks. These blocks are linked using cryptogrphy. Each block in the chain holds the cryptographic hash of the previous block, a timestamp, in addition to the transaction data. The Merkle tree structure is used to represent this. Satoshi Nakamoto (true identity unknown) is the person or the name used by a group of people who conceptualised the blockchain in the year 2008.
The blockchain is used across a spectrum of domains these days, and there are many projects/platforms based on it (Figure 1).

Figure 1: Blockchain projects and platforms

This article explores an important open source blockchain project called Corda, which has been developed by R3 along with the participation of 200 technology and industry partners.

Figure 2: Corda’s features

The primary features of Corda (Figure 2) are listed below:

  • Java/JVM language based smart contracts.
  • The availability of the Flow framework, which enables managing communication and negotiation between parties.
  • Provision of a notary infrastructure to validate transactions without global broadcast.
  • Enables the development of CorDapps.
  • Built using Kotlin targeting JVM.

A simple introduction to Corda is available in the two-minute video provided by the official Corda documentation https://vimeo.com/205410473.

The terminology associated with Corda is vast and covering the entire list of terms would be impossible in this article due to space constraints. Here are some of the most commonly used terms:

  • The network
  • The ledger
  • States
  • Transactions
  • Contracts
  • Flows
  • Consensus
  • Notaries
  • Vault
  • Time windows
  • Oracles
  • Nodes
  • Transaction tear-offs
  • Trade-offs
  • Deterministic JVM

(Detailed instructions on each of these terms are available at https://docs.corda.net/key-concepts.html. Video based illustrations of these terms make it easier to understand them.)

The Corda network
Corda is a peer-to-peer network of nodes. Each node executes the Corda software and the Corda applications, which are termed CorDapps. The communication between these nodes is point-to-point and they are encrypted with the transport layer security. The core point here is that data is shared only on a need-to-know basis, which removes the global broadcasts.

The ledger
In Corda, the data is not stored in a single centralised location. Each participating node holds its own database of known facts. This creates a situation where each peer only sees a subset of facts; no peer can be aware of the ledger in its entirety.

Corda DemoBench
The Corda DemoBench is a standalone desktop application. The DemoBench makes the configuration and launch of local Corda Nodes easy. Detailed instructions on DemoBench are available at https://docs.corda.net/demobench.html.

  • Each node must have a unique name to identify it. The first node is the notary. So in this node, only the notary services are available. For the remaining nodes, other built-in services can be selected.
  • Each new node is launched in the terminal emulator by DemoBench, which displays simple statistics about each node such as its cash balance.
Figure 3: CorDapp components

The CorDapp
The CorDapps are Corda Distributed Applications. These apps run on the Corda platforms. The objective of the CorDapp is to allow nodes to reach an agreement on updates to the ledger. This is achieved by the flow definition, which the Corda node owners can invoke over RPC.
The CorDapp structure is similar to a set of JAR files containing class definitions coded in Java/Kotlin. The components of these class definitions are as follows.

  • Flows: These define a routine for the node to run. They are usually for making updates to the ledger.
  • States: These are used to define facts on which agreements are reached.
  • Contracts: They constitute a valid ledger update.
  • Services: These provide the long-lived utilities within the node.
  • The Serialization Whitelist.

Software requirements
The CorDapp development software requirements are:

  • Java 8 JVM (at least version 8u171)
  • Gradle
  • IntelliJ IDEA

Detailed setup instructions are available at https://docs.corda.net/getting-set-up.html.
The CorDapp can be executed in two ways. One is to execute it via the terminal and the other is to run it via IntelliJ.

Building your own CorDapp
CorDapp generally defines three items, as listed below:

  • States: These are shared facts that are written to the ledger.
  • Flows: This refers to the procedure to be carried out for specific updates to the ledger.
  • Contracts: These are constraints on how the state of a given type can evolve over time.

The CorDapp template can be downloaded with the following code.
For Java:

git clone https://github.com/corda/cordapp-template-java.git; cd cordapp-template-java

For Kotlin:

git clone https://github.com/corda/cordapp-template-kotlin.git; cd cordapp-template-kotlin

Let’s take a look at a sample of the State and Flow code. A sample TemplateState.java is shown below:

// Add this import:
import net.corda.core.identity.Party;

// Replace TemplateState’s definition with:
public class IOUState implements ContractState {
private final int value;
private final Party lender;
private final Party borrower;

public IOUState(int value, Party lender, Party borrower) {
this.value = value;
this.lender = lender;
this.borrower = borrower;
}

public int getValue() {
return value;
}

public Party getLender() {
return lender;
}

public Party getBorrower() {
return borrower;
}

@Override
public List<AbstractParty> getParticipants() {
return Arrays.asList(lender, borrower);
}
}

A sample of FlowLogic is shown below:

// Add these imports:
import net.corda.core.contracts.Command;
import net.corda.core.identity.Party;
import net.corda.core.transactions.SignedTransaction;
import net.corda.core.transactions.TransactionBuilder;

// Replace Initiator’s definition with:
@InitiatingFlow
@StartableByRPC
public class IOUFlow extends FlowLogic<Void> {
private final Integer iouValue;
private final Party otherParty;

/**
* The progress tracker provides checkpoints indicating the progress of the flow to observers.
*/
private final ProgressTracker progressTracker = new ProgressTracker();

public IOUFlow(Integer iouValue, Party otherParty) {
this.iouValue = iouValue;
this.otherParty = otherParty;
}

@Override
public ProgressTracker getProgressTracker() {
return progressTracker;
}

/**
* The flow logic is encapsulated within the call() method.
*/
@Suspendable
@Override
public Void call() throws FlowException {
// We retrieve the notary identity from the network map.
Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);

// We create the transaction components.
IOUState outputState = new IOUState(iouValue, getOurIdentity(), otherParty);
Command command = new Command<>(new TemplateContract.Commands.Action(), getOurIdentity().getOwningKey());

// We create a transaction builder and add the components.
TransactionBuilder txBuilder = new TransactionBuilder(notary)
.addOutputState(outputState, TemplateContract.ID)
.addCommand(command);

// Signing the transaction.
SignedTransaction signedTx = getServiceHub().signInitialTransaction(txBuilder);

// Creating a session with the other party.
FlowSession otherPartySession = initiateFlow(otherParty);

// We finalise the transaction and then send it to the counterparty.
subFlow(new FinalityFlow(signedTx, otherPartySession));

return null;
}
}

The corresponding Kotlin code is also available. The complete Hello World tutorial along with instructions on how to modify and execute it is provided at https://docs.corda.net/hello-world-introduction.html .
This article has provided only an introduction to Corda. The quantum of resources available with Corda is larger. If you are interested in the blockchain, try exploring Corda for features that match your requirements.

LEAVE A REPLY

Please enter your comment!
Please enter your name here