Running Your First CorDapp
The CorDapp template includes flows
Communication between participants in an application network is peer-to-peer using flows.
and tests for a very simple CorDapp
Corda Distributed Application. A Java (or any JVM targeting language) application built using the Corda build toolchain and CorDapp API to solve some problem that is best solved in a decentralized manner.
, which you can run out of the box. The code for the flow can be found in the src/main/kotlin.com.r3.developers.cordapptemplate.flowexample.workflows.MyFirstFlow.kt
file. This is also the code described in the first flow section. This section describes how to run, test, and deploy this flow. It contains the following:
Starting the Corda Combined Worker
To run the flow, you must first start a local combined worker version of Corda. The CorDapp template includes helper Gradle tasks to do this.
The startCorda
task runs in an Intellij ‘Run’ window. After about one minute, it shows the following output:
The startCorda
task continues to run whilst the Corda cluster is running. It stops when the cluster is shut down.
Currently, we do not have a liveness detector for Corda in the CorDapp template so we check liveness by manually hitting an endpoint. You can use the listVNodes helper to do this.
Testing Liveness and Swagger
Corda exposes HTTP REST API APIs allow different software applications to communicate with each other and share data in a standardized and structured way. endpoints for interacting with itself and the CorDapps running on it. It also exposes a Swagger interface which is described in the following sections.
Displaying the Swagger UI
To display the Swagger UI, use the following link:
https://localhost:8888/api/v5_2/swagger#/
If Corda has started, the Swagger UI displays:
If Corda has not started yet, the page will not load. If the Swagger UI is already open whilst starting Corda, you must hit an endpoint to test liveness of Corda.
Authorizing Swagger
To access the Corda cluster, you must authorize Swagger:
- Click the green Authorize button.The Available authorizations window is displayed.
- If necessary, click Logout.
- Enter the username and password. For the purposes of experimental development, the username for the combined worker is set to
admin
and the password isadmin
. - Click Authorise and then Close.
Hitting Endpoints
Once authorized, you can start hitting endpoints. The easiest one to try is /cpi
because it is the first one on the Swagger page and requires no arguments:
- Expand the
GET /cpi
row and click Try it out. - Click the Execute button to hit the endpoint.
If Corda has started you should see a response like this:As we have not uploaded any CPIs yet, the returned list of CPIs is empty.
If Corda has not started yet, Swagger will return an error:If this occurs, you either have not started Corda, Corda has not finished starting, or something has gone wrong. If something has gone wrong, you should try again or reset the environment and start again.Each time you start Corda for the specific combined worker development environment, it is a fresh instance. There is no persistence of state between restarts.
Deploying a CorDapp
You can use the MyFirstFlow
flow to build a CorDapp, without any further work:
- Click the
vNodesSetup
Gradle task:This task runs a series of Gradle tasks to:- Build the CPB Corda Package Bundle. A signed ZIP/JAR collection of CPKs that forms a complete application suite and contains all the code that a virtual node must operate, minus the specific network details.
- Create the GroupPolicy (Application Network definition)
- Generate signing keys to sign the CPB and CPI Corda Package Installer. A signed ZIP/JAR combination of a CPB and a Group Policy File that defines not only the application code that a virtual node will run, but also the details of the MGM with which to register, and the details of network PKI requirements.
- Build the CPI
- Sign the CPI
- Upload the CPI to Corda
- Create and register the virtual nodes with the CPISome of these tasks only need to run once and will not run again if not required.You should now be able to start
MyFirstFlow
from the Swagger UI.
Starting Your First Flow
To run your first flow:
Find the
holdingidentityshorthash
for the virtual node The combination of the context of a user and the ephemeral compute instances created to progress a transaction on that identity's behalf. you want to trigger the flow on. You can do this by running thelistVnodes
Gradle task to display a list of the configured virtual nodes:The 12 digit hash is theholdingidentityshorthash
that acts as the unique identifier for a virtual node.Expand the
POST /flow/{holdingidentityshorthash}
endpoint in the Flow Management API section in Swagger and click Try it out.Enter the hash and the
requestBody
and click Execute.
requestBody code:
{
"clientRequestId": "r1",
"flowClassName": "com.r3.developers.cordapptemplate.flowexample.workflows.MyFirstFlow",
"requestBody": {
"otherMember":"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB"
}
}
ClientRequestId
is a unique identifier for the request to start a flow.flowClassName
is the fully qualified path to the flow class you want to run.requestBody
is the set of arguments you pass to the flow.Swagger should display the following response:
Note, if you forget to change the ClientRequestId
on subsequent attempts to run the flow, the following error message is displayed:
Because the API is asynchronous, at this stage you only receive the confirmation START_REQUESTED
. There is no indication if the flow has been successful. To find out the status of the flow, you must check the flow status.
Checking the Flow Status
To check the flow status:
- Expand the
GET /flow/{holdingidentityshorthash}/{clientrequestid}
endpoint in Swagger and click Try it out. - Enter the hash and the
requestid
used when starting the flow and click Execute.If the flow is successful, you will see the following response:You will learn more about the flowResult of “Hello Alice best wishes from Bob” in Your first flow.
Was this page helpful?
Thanks for your feedback!
Chat with us
Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.
Propose documentation improvements directly
Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.
We're sorry this page wasn't helpful. Let us know how we can make it better!
Chat with us
Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.
Create an issue
Create a new GitHub issue in this repository - submit technical feedback, draw attention to a potential documentation bug, or share ideas for improvement and general feedback.
Propose documentation improvements directly
Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.