In this article, we will guide you through the steps of designing a CorDapp. We will do so by designing a simple badge CorDapp together. Note: If you are new to the Corda community, please watch the Corda Introduction video.
In the badge CorDapp, you will be able to issue a “badge” from the issuer node to your node. Once you received the badge, you will have the option to trigger a show-off ? action. However, the number of available show-offs is limited, so when you run out of the show-off balance, you will no longer be able to do it. Sounds interesting? Let’s get to it!
Designing the CorDapp
A big part of software development is designing/planning. Nowadays, a large number of software companies will take the agile software development pattern, which adding new functions on the go. However, keep in mind, when you develop a smart contract running on a decentralized network. Each software update would need a network-level agreement. It is doable but it will create a much more ripple effect than it will on a centralized managed system. With that said, when we design the decentralized app, we should be as comprehensive as we can to avoid future major changes.
First thing first — The Network Participants
In our introduction video, we begin talking about Corda via a simple network of Alice, Bob, and Carl. That would be the same case when we design our CorDapp. That is, we need to think about the participants of the network. It doesn’t mean we will list out all of the participants and cannot onboard any new customer in the future, we just need to plan for the required participants in the network.
? In our Badge CorDapp, we want to achieve the action of issue a badge from one node to another node (the me-node). Therefore, I would like to have 3 required nodes to start the network with:
- Issuer Node
- PeterNode (Feel free to change it to your name ?)
- Bystander Node (We want this node to show Corda’s P2P private transaction scheme, where he is in the network but he doesn’t know anything about the transaction between IssuerNode and PeterNode)
How Blocks chain Up — Corda State
In the Corda introduction video, we explained that “in a Corda system, Corda States are the blocks and it chains up via transactions.” After initial creation, States will be either consumed or updated in later transactions. You can include as much information as you want in a Corda State. It is the lego block of your system.
? Now, let us design the Corda States for the Badge CorDapp. Since we are passing along the badge in our app, the Corda state will indeed be a badge! Let’s list some attributes of a badge:
1. Name 2. Badge ID 3. Badge Issue Date 4. Issue agency 5. Receiver 6. Badge Description 7. Show-off counts balance ?
What do you want to do with the States — Corda Flows
In the Corda system, the flows define the actions of the app. Whenever you want to initiate a transaction, your node will invoke the designed flow to execute. It is also the flow that gets triggered via RPC client from your existing infrastructure.
? Back to our Badge CorDapp, in our brief description, we mentioned that we want to have two actions:
- Issuance flow takes parameters of recipient name, badge Description, and show-off counts balance.
- Show-off ? flow takes parameters of Badge ID
Under what rules shall we execute a transaction — Corda Contracts
In the Corda system, the contracts define the regime for different transactions. As we recall, transactions in Corda are only shared between the transaction participants, therefore, the transaction validation is in the hands of these participants. There needs to be a series set of rules to regulate transactions and reduce the risk of having bad transactions.
? In our Badge CorDapp, we could come up with arbitrary rules such as:
- Any Issuance action, the issuing agency has to be the Issuer Node
- Any show-off action, the show-off counts balance has to be more than one.
So far, you went through the application architecting of a CorDapp. This is the very first step of CorDapp development. Once we have the architecture of our CorDapp, the second step is implementation. Stay tuned to continue learning about the implementation in our next article: How to implement a well designed CorDapp.
Peter Li is a Developer Evangelist at R3, an enterprise blockchain software firm working with a global ecosystem of more than 350 participants across multiple industries from both the private and public sectors to develop on Corda, its open-source blockchain platform, and Corda Enterprise, a commercial version of Corda for enterprise usage.
Follow us on twitter here.