2017-06-16 13:05:52 +00:00
|
|
|
|
.. highlight:: kotlin
|
|
|
|
|
.. raw:: html
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="_static/jquery.js"></script>
|
|
|
|
|
<script type="text/javascript" src="_static/codesets.js"></script>
|
|
|
|
|
|
|
|
|
|
The CorDapp Template
|
|
|
|
|
====================
|
|
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
|
When writing a new CorDapp, you’ll generally want to base it on the standard templates:
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
|
* The `Java Cordapp Template <https://github.com/corda/cordapp-template-java>`_
|
|
|
|
|
* The `Kotlin Cordapp Template <https://github.com/corda/cordapp-template-kotlin>`_
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
|
The Cordapp templates provide the required boilerplate for developing a CorDapp, and allow you to quickly deploy your
|
|
|
|
|
CorDapp onto a local test network of dummy nodes to test its functionality.
|
|
|
|
|
|
|
|
|
|
CorDapps can be written in both Java and Kotlin, and will be providing the code in both languages in this tutorial.
|
|
|
|
|
|
|
|
|
|
Note that there's no need to download and install Corda itself. Corda V1.0's required libraries will be downloaded
|
|
|
|
|
automatically from an online Maven repository.
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
|
|
|
|
Downloading the template
|
|
|
|
|
------------------------
|
2017-11-16 15:31:52 +00:00
|
|
|
|
To download the template, open a terminal window in the directory where you want to download the CorDapp template, and
|
|
|
|
|
run the following command:
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
2017-10-02 14:01:19 +00:00
|
|
|
|
.. code-block:: bash
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
2017-08-16 07:36:00 +00:00
|
|
|
|
git clone https://github.com/corda/cordapp-template-java.git ; cd cordapp-template-java
|
2017-07-28 08:13:53 +00:00
|
|
|
|
|
|
|
|
|
*or*
|
|
|
|
|
|
2017-08-16 07:36:00 +00:00
|
|
|
|
git clone https://github.com/corda/cordapp-template-kotlin.git ; cd cordapp-template-kotlin
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
|
Opening the template in IntelliJ
|
|
|
|
|
--------------------------------
|
|
|
|
|
|
|
|
|
|
Once the template is download, open it in IntelliJ by following the instructions here:
|
|
|
|
|
https://docs.corda.net/tutorial-cordapp.html#opening-the-example-cordapp-in-intellij.
|
|
|
|
|
|
2017-06-16 13:05:52 +00:00
|
|
|
|
Template structure
|
|
|
|
|
------------------
|
2017-12-13 16:22:40 +00:00
|
|
|
|
The template has a number of files, but we can ignore most of them. We will only be modifying the following files:
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
|
|
|
|
.. container:: codeset
|
|
|
|
|
|
|
|
|
|
.. code-block:: java
|
|
|
|
|
|
|
|
|
|
// 1. The state
|
2017-12-13 16:22:40 +00:00
|
|
|
|
cordapp-contracts-states/src/main/java/com/template/TemplateState.java
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
|
// 2. The flow
|
2017-12-13 16:22:40 +00:00
|
|
|
|
cordapp/src/main/java/com/template/TemplateFlow.java
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
2017-08-17 11:02:44 +00:00
|
|
|
|
.. code-block:: kotlin
|
|
|
|
|
|
2017-12-13 16:22:40 +00:00
|
|
|
|
// 1. The state
|
|
|
|
|
cordapp-contracts-states/src/main/kotlin/com/template/StatesAndContracts.kt
|
|
|
|
|
|
|
|
|
|
// 2. The flow
|
|
|
|
|
cordapp/src/main/kotlin/com/template/App.kt
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
|
Clean up
|
|
|
|
|
--------
|
|
|
|
|
To prevent build errors later on, we should delete the following files before we begin:
|
|
|
|
|
|
2017-12-13 16:22:40 +00:00
|
|
|
|
* Java: ``cordapp/src/main/java/com/template/TemplateClient.java``
|
2017-10-16 13:39:28 +00:00
|
|
|
|
|
2017-12-13 16:22:40 +00:00
|
|
|
|
* Kotlin: ``cordapp/src/main/kotlin/com/template/TemplateClient.kt``
|
2017-10-16 13:39:28 +00:00
|
|
|
|
|
2017-06-16 13:05:52 +00:00
|
|
|
|
Progress so far
|
|
|
|
|
---------------
|
2017-11-16 15:31:52 +00:00
|
|
|
|
We now have a template that we can build upon to define our IOU CorDapp. Let's start by defining the ``IOUState``.
|