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
|
|
|
|
|
====================
|
|
|
|
|
|
2018-11-13 11:50:24 +00:00
|
|
|
|
When writing a new CorDapp, you’ll generally want to start from one of 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
|
|
|
|
|
2018-11-13 11:50:24 +00:00
|
|
|
|
The Cordapp templates provide the boilerplate for developing a new CorDapp. CorDapps can be written in either Java or Kotlin. We will be
|
|
|
|
|
providing the code in both languages throughout this tutorial.
|
2017-11-16 15:31:52 +00:00
|
|
|
|
|
2018-11-13 11:50:24 +00:00
|
|
|
|
Note that there's no need to download and install Corda itself. The required libraries are automatically downloaded from an online Maven
|
|
|
|
|
repository and cached locally.
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
|
|
|
|
Downloading the template
|
|
|
|
|
------------------------
|
2018-11-13 11:50:24 +00:00
|
|
|
|
Open a terminal window in the directory where you want to download the CorDapp template, and run the following command:
|
|
|
|
|
|
|
|
|
|
.. container:: codeset
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
2018-11-13 11:50:24 +00:00
|
|
|
|
.. code-block:: java
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
2018-11-13 11:50:24 +00:00
|
|
|
|
git clone https://github.com/corda/cordapp-template-java.git ; cd cordapp-template-java
|
2017-07-28 08:13:53 +00:00
|
|
|
|
|
2018-11-13 11:50:24 +00:00
|
|
|
|
.. code-block:: kotlin
|
2017-07-28 08:13:53 +00:00
|
|
|
|
|
2018-11-13 11:50:24 +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
|
|
|
|
|
------------------
|
2018-11-13 11:50:24 +00:00
|
|
|
|
For this tutorial, 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
|
2018-11-08 10:19:03 +00:00
|
|
|
|
cordapp/src/main/java/com/template/Initiator.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
|
2018-11-08 10:19:03 +00:00
|
|
|
|
cordapp/src/main/kotlin/com/template/Flows.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``.
|