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
|
|
|
|
|
====================
|
|
|
|
|
|
|
|
|
|
When writing a new CorDapp, you’ll generally want to base it on the
|
2017-07-28 08:13:53 +00:00
|
|
|
|
`Java Cordapp Template <https://github.com/corda/cordapp-template-java>`_ or the equivalent
|
|
|
|
|
`Kotlin Cordapp Template <https://github.com/corda/cordapp-template-kotlin>`_. The Cordapp Template allows you to
|
|
|
|
|
quickly deploy your CorDapp onto a local test network of dummy nodes to evaluate its functionality.
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
|
|
|
|
Note that there's no need to download and install Corda itself. As long as you're working from a stable Milestone
|
|
|
|
|
branch, the required libraries will be downloaded automatically from an online repository.
|
|
|
|
|
|
|
|
|
|
If you do wish to work from the latest snapshot, please follow the instructions
|
|
|
|
|
`here <https://docs.corda.net/tutorial-cordapp.html#using-a-snapshot-release>`_.
|
|
|
|
|
|
|
|
|
|
Downloading the template
|
|
|
|
|
------------------------
|
|
|
|
|
Open a terminal window in the directory where you want to download the CorDapp template, and run the following commands:
|
|
|
|
|
|
2017-10-02 10:33:47 +00:00
|
|
|
|
.. code-block:: bash
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
|
|
|
|
# Clone the template from GitHub:
|
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
|
|
|
|
|
|
|
|
|
Template structure
|
|
|
|
|
------------------
|
2017-08-16 07:36:00 +00:00
|
|
|
|
We can write our CorDapp in either Java or Kotlin, and will be providing the code in both languages throughout. To
|
2017-08-17 11:02:44 +00:00
|
|
|
|
implement our IOU CorDapp in Java, we'll need to modify three files. For Kotlin, we'll simply be modifying the
|
|
|
|
|
``App.kt`` file:
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
|
|
|
|
.. container:: codeset
|
|
|
|
|
|
|
|
|
|
.. code-block:: java
|
|
|
|
|
|
|
|
|
|
// 1. The state
|
2017-10-16 15:45:48 +00:00
|
|
|
|
src/main/java/com/template/TemplateState.java
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
|
|
|
|
// 2. The contract
|
2017-10-16 15:45:48 +00:00
|
|
|
|
src/main/java/com/template/TemplateContract.java
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
|
|
|
|
// 3. The flow
|
2017-10-16 15:45:48 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
src/main/kotlin/com/template/App.kt
|
2017-06-16 13:05:52 +00:00
|
|
|
|
|
2017-10-16 15:45:48 +00:00
|
|
|
|
To prevent build errors later on, you should delete the following file:
|
|
|
|
|
|
|
|
|
|
* Java: ``src/test/java/com/template/FlowTests.java``
|
|
|
|
|
* Kotlin: ``src/test/kotlin/com/template/FlowTests.kt``
|
|
|
|
|
|
2017-06-16 13:05:52 +00:00
|
|
|
|
Progress so far
|
|
|
|
|
---------------
|
|
|
|
|
We now have a template that we can build upon to define our IOU CorDapp.
|
|
|
|
|
|
2017-07-06 13:23:52 +00:00
|
|
|
|
We'll begin writing the CorDapp proper by writing the definition of the ``IOUState``.
|