Part 1: How I Created A CorDapp In 3 Steps

This article will take you through all you need to know before you have your first corDapp up and running. I have divided three steps into three different articles, and this is the first article describing the first step. Soon, I will publish the next steps in my upcoming articles.

If you are completely new to Corda then please refer my previous articles to understand what Corda is and use cases of Corda. So, you will get the answer to all your questions about Corda. Below is the link to the article.

R3 Corda: Get started with Corda

And here is the other article, where I have tried to answer basic questions that arise on a learning path of Corda.

How to Get started learning Corda: 10 Beginners FAQs

Step 1: Installation and setup

First, we need to ensure we have all the prerequisites are installed, which are:

Java 8 JVK – We require at least version 8u171, but do not currently support Java 9 or higher.

IntelliJ IDEA – IntelliJ is an IDE that offers strong support for Kotlin and Java development. We support versions of 2017.x, 2018.x, and 2019.x (with Kotlin plugin version 1.2.71).

Git – Git to download the templates and push your corDapp as a repository.

Gradle – Install Gradle version 5.4.1. If you are using a supported Corda sample, the included Gradle script should install Gradle automatically.

Our use-case:

BookMyStay is online hotel booking services which allow its customer to book rooms online on HotelHeaven’s hotel chain. As per the agreement, BookMyStay collects certain information from its customer and sends it to HotelHeaven, HotelHeaven in return sends an acknowledgment to BookMyStay. So, here we are building an application BookingCorDapp for BookMyStay.

There are two parties in BookingCorDapp.

1.   BookMyStay

2.   HotelHeaven

BookMyStay will send the following details to HotelHeaven to book a stay as requested by their customer.

  • Customer name, Customer Age
  • Check-In Date, Check-out Date
  • Room Type, Original Room Rate
  • Merchant Credit Card Number, Credit Card exp date.
  • Credit Card Amount (After 15% commission deduction on room rate)

7 constraints should be met before sending booking detail to HotelHeaven:

1.   Customer Age should be greater than 18.

2.   Check-in and Check-Out date Should be Future Date.

3.   The check-out date should be greater than a check-in date.

4.   Room Type format is from this only: K, NK, DD, NDD

5.   After commission price should 85% of Original room price.

6.   The credit card number length should be 16.

7.   Credit Card Exp date should not be in the past.

Let’s get our hands dirty: Now let us create our CorDapp using The CorDapp Template. For that, we have to download corda template from GitHub and import it into IntelliJ. The standard template can be downloaded from the below link:

Java CorDapp Template

Once the template is download, open it in IntelliJ by following the instructions here:

  • Open IntelliJ
  • A splash screen will appear. Click open, navigate to and select the cordapp-example folder, and click OK
  • Once the project is open, click File, then Project Structure. Under Project SDK, set the project SDK by clicking New…, clicking JDK, and navigating to C:\Program Files\Java\jdk1.8.0_XXX on Windows or Library/Java/JavaVirtualMachines/jdk1.8.XXX on MacOSX (where XXX is the latest minor version number). Click Apply followed by OK
  • Again under File then Project Structure, select Modules. Click +, then Import-Module, then select the corDapp-example folder and click Open. Choose to Import module from external model, select Gradle, click Next then Finish (leaving the defaults) and OK
  • Gradle will now download all the project dependencies and perform some indexing. This usually takes a minute or so.

The Gradle project contains 3 main modules like in a bellow figure:

No alt text provided for this image

1.    Contracts: It defines the contractual validity of the CorDapp. You can read more about it hereStates are created in the same module, The actual information stored in the ledger.

2.    Workflows: The flows enable automated agreeing to the ledger states. Detailed documentation can be found on the Corda website.

3.    Clients: The client defines classes that can be used to interact with the CorDapp in a production environment.

Setup – CorDapp environment using build.gradle:

Define the Corda Network. Our Booking Application has two Parties and a Notary. So we define this network configuration in the deploy nodes task of the Gradle build file. From PartyA and PartyB, we will change it to BookMyStay and HotelHeaven.

No alt text provided for this image

Until now we have our platform ready, we are ready to code…

We will continue in the next article: “Steps to build BookingCorDapp “.

Link for Part 2: How I created a CorDapp in 3 steps

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories