Running the Chat CorDapp

This section describes how to run the UTXO Unspent Transaction Output. The unspent output of a cryptocurrency transaction, representing the amount of digital currency that has not been spent and is available for use in future transactions. chat 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. . It contains the following:
- Configuring the Application Network (Virtual Nodes)
- Deploying the CorDapp
- Using Swagger
- Typical Set of Flows
Configuring the Application Network

The CorDapp template is configured to create a five party application network The set of all possible entities onboarded according to the rules of the network. Application networks enable people and businesses to interact with each other on Corda. required to run the Chat 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. , including virtual nodes for Alice, Bob, Charlie, Dave, and a notary Corda’s uniqueness consensus service. The notary’s primary role is to prevent double-spends by ensuring each transaction contains only unique unconsumed input states. . To change the network configuration, see Configuring the Network Participants.
Deploying the CorDapp

To deploy and run the CorDapp, follow the same steps as outlined in Running Your First CorDapp.
However, when you come to trigger the flows
Communication between participants in an application network is peer-to-peer using flows.
, you must trigger the appropriate ChatFlow
rather than MyFirstFlow
.
Using Swagger

For this walkthrough, we assume you are using the Swagger GUI
to trigger flows. For each flow we use the Flow Management section of the API.
You must know the holdingidentityshorthash
for both Alice and Bob’s nodes. You can retrieve this by running the listVNodes
Gradle helper in the corda-runtime-plugin-queries
section of the gradle helper tasks.
The task returns something similar to this:

The vnode holdingidentityshorthashes
(short hashes) are the 12 digit hex numbers. In the above example, Alice’s short hash is “253501665E9D” and Bob’s is “86BC1B1A18AA”. Whenever the API requires the short hash, substitute the appropriate number depending on which vnode you want to run the flow on.
For running the flows use the POST: /flow/{holdingidentityshorthash}/
endpoint. This requires a request body to be provided which includes:
clientRequestId
to uniquely identify the requestflowClassName
which provides the fully qualified name of the flow to be triggeredrequestBody
which provides the input arguments for the flow
For example:
{
"clientRequestId": "create-1",
"flowClassName": "com.r3.developers.cordapptemplate.utxoexample.workflows.CreateNewChatFlow",
"requestBody": {
"chatName":"Chat with Bob",
"otherMember":"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB",
"message": "Hello Bob"
}
}
Swagger also gives the curl command which you can use to run the request directly from the command line, for example:
curl -X 'POST' \
'https://localhost:8888/api/v5_2/flow/253501665E9D' \
-H 'accept: application/json' \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
-H 'Content-Type: application/json' \
-d '{
"clientRequestId": "create-1",
"flowClassName": "com.r3.developers.cordapptemplate.utxoexample.workflows.CreateNewChatFlow",
"requestBody": {
"chatName":"Chat with Bob",
"otherMember":"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB",
"message": "Hello Bob"
}
}'
If the flow has been successfully started, Swagger shows “START REQUESTED” response, for example:
{
"holdingIdentityShortHash": "253501665E9D",
"clientRequestId": "create-1",
"flowId": null,
"flowStatus": "START_REQUESTED",
"flowResult": null,
"flowError": null,
"timestamp": "2023-03-20T17:23:18.998Z"
}
If something has gone wrong, Swagger shows an error response.
For polling for the result of a flow, use the GET: /flow/{holdingidentityshorthash}/{clientrequestid}/result
endpoint. This requires the short hash of the node the flow was run against and the clientRequestId
specified when the flow was run.
The curl version is:
curl -X 'GET' \
'https://localhost:8888/api/v5_2/flow/253501665E9D/create-1/result' \
-H 'accept: application/json' \
-H 'Authorization: Basic YWRtaW46YWRtaW4='
If the flow has run successfully, this returns a “COMPLETED” status together with the flowResult
.
{
"holdingIdentityShortHash": "253501665E9D",
"clientRequestId": "create-1",
"flowId": "a1109c50-b455-48e0-adf2-f1811e420bb6",
"flowStatus": "COMPLETED",
"flowResult": "SHA-256D:AA9C38E9EE5EA62595AD68F19DD2BA360CC665D8086045E7FFB4E7FCD3CDC24E",
"flowError": null,
"timestamp": "2023-03-20T17:28:49.213Z"
}
Typical Set of Flows

The following is a typical set of flows for a conversation between Alice and Bob:
Alice creates a new chat using the
POST: /flow/{holdingidentityshorthash}
endpoint and the following code:{ "clientRequestId": "create-1", "flowClassName": "com.r3.developers.cordapptemplate.utxoexample.workflows.CreateNewChatFlow", "requestBody": { "chatName":"Chat with Bob", "otherMember":"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB", "message": "Hello Bob" } }
Followed by polling for status with
GET: /flow/{holdingidentityshorthash}/{clientrequestid}
. This should return “COMPLETED” after a short delay.Bob lists his chats that he is a participant in using the
POST: /flow/{holdingidentityshorthash}
endpoint and the following code:{ "clientRequestId": "list-1", "flowClassName": "com.r3.developers.cordapptemplate.utxoexample.workflows.ListChatsFlow", "requestBody": {} }
Followed by polling for the status with
GET: /flow/{holdingidentityshorthash}/{clientrequestid}
. This should return “COMPLETED” after a short delay. The output shows theflowResult
with the single chat that Bob is a participant in. From this he can get theid
number 674276c9-f311-43a6-90b8-73439bc7e28b and update the chat.{ "holdingIdentityShortHash": "86BC1B1A18AA", "clientRequestId": "list-1", "flowId": "fee5d450-4796-49ec-9347-247a9dfd4c5b", "flowStatus": "COMPLETED", "flowResult": "[{\"id\":\"674276c9-f311-43a6-90b8-73439bc7e28b\",\"chatName\":\"Chat with Bob\",\"messageFromName\":\"CN=Alice, OU=Test Dept, O=R3, L=London, C=GB\",\"message\":\"Hello Bob\"}]", "flowError": null, "timestamp": "2023-01-18T10:47:13.104870Z" }
Bob updates the chat twice using the
POST: /flow/{holdingidentityshorthash}
endpoint and the following code:{ "clientRequestId": "update-1", "flowClassName": "com.r3.developers.cordapptemplate.utxoexample.workflows.UpdateChatFlow", "requestBody": { "id":"674276c9-f311-43a6-90b8-73439bc7e28b", "message": "Hi Alice" } }
Remember to update theid
or you will get an error or update the wrong chat.Poll for status with
GET: /flow/{holdingidentityshorthash}/{clientrequestid}
and the following code:{ "clientRequestId": "update-2", "flowClassName": "com.r3.developers.cordapptemplate.utxoexample.workflows.UpdateChatFlow", "requestBody": { "id":"674276c9-f311-43a6-90b8-73439bc7e28b", "message": "How are you today?" } }
Wait for “COMPLETED” status.
Alice uses the
POST: /flow/{holdingidentityshorthash}
endpoint and the following code to get theid
of the chat with Bob:{ "clientRequestId": "list-2", "flowClassName": "com.r3.developers.cordapptemplate.utxoexample.workflows.ListChatsFlow", "requestBody": {} }
Poll for status with
GET: /flow/{holdingidentityshorthash}/{clientrequestid}
and wait for “COMPLETED” status.Alice checks the history on the chat with Bob using the
POST: /flow/{holdingidentityshorthash}
endpoint and the following code:{ "clientRequestId": "get-1", "flowClassName": "com.r3.developers.cordapptemplate.utxoexample.workflows.GetChatFlow", "requestBody": { "id":"674276c9-f311-43a6-90b8-73439bc7e28b", "numberOfRecords":"4" } }
Poll for status with
GET: /flow/{holdingidentityshorthash}/{clientrequestid}
and wait for “COMPLETED” status. TheflowResult
shows the previous messages for the chat in reverse order:{ "holdingIdentityShortHash": "253501665E9D", "clientRequestId": "get-1", "flowId": "25932ec9-ff81-4b58-bf7c-c21e67487cf9", "flowStatus": "COMPLETED", "flowResult": "[{\"messageFrom\":\"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB\",\"message\":\"How are you today?\"},{\"messageFrom\":\"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB\",\"message\":\"Hi Alice\"},{\"messageFrom\":\"CN=Alice, OU=Test Dept, O=R3, L=London, C=GB\",\"message\":\"Hello Bob\"}]", "flowError": null, "timestamp": "2023-01-18T11:02:58.526047Z" }
Alice replies to Bob using the
POST: /flow/{holdingidentityshorthash}
endpoint and the following code:{ "clientRequestId": "update-4", "flowClassName": "com.r3.developers.cordapptemplate.utxoexample.workflows.UpdateChatFlow", "requestBody": { "id":"674276c9-f311-43a6-90b8-73439bc7e28b", "message": "I am very well thank you" } }
Poll for status with
GET: /flow/{holdingidentityshorthash}/{clientrequestid}
and wait for “COMPLETED” status.Bob gets the chat history limited it to the last 2 entries using the
POST: /flow/{holdingidentityshorthash}
endpoint and the following code:{ "clientRequestId": "get-2", "flowClassName": "com.r3.developers.cordapptemplate.utxoexample.workflows.GetChatFlow", "requestBody": { "id":"674276c9-f311-43a6-90b8-73439bc7e28b", "numberOfRecords":"2" } }
Poll for status with
GET: /flow/{holdingidentityshorthash}/{clientrequestid}
and wait for “COMPLETED” status. TheresultData
should show the last two messages in the chat:{ "holdingIdentityShortHash": "86BC1B1A18AA", "clientRequestId": "get-2", "flowId": "7dd326dc-31b5-42b7-b20b-ca8512b076db", "flowStatus": "COMPLETED", "flowResult": "[{\"messageFrom\":\"CN=Alice, OU=Test Dept, O=R3, L=London, C=GB\",\"message\":\"I am very well thank you\"},{\"messageFrom\":\"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB\",\"message\":\"How are you today?\"}]", "flowError": null, "timestamp": "2023-01-18T11:09:13.282302Z" }
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.