Are you familiar with Corda? If so, you may have wondered how to represent application users on Corda. This is supposed to be a trivial requirement for any use case. And coming from other blockchain platforms, where you could easily create a user account on the node, it may seem like a big piece was missing in Corda. However, Corda was designed with a different philosophy in mind. Initially, it was supposed to be used and hosted by large enterprises to communicate with other such large enterprises.
Considering Corda’s original purpose, there was no need to have multiple identities hosted on the node. This worked well until Corda was increasingly adopted in more and more diverse industries. As it started becoming a more general-purpose DLT platform, the need for accounts was seen as a major concern, and thus Corda Accounts was released.
But what exactly are accounts in Corda and how do they work under the hood?
What is an Account in Corda?
Though accounts are meant to represent multiple identities in the node, they are not Corda identities; the node still has a single unique legal identity. This means accounts are not registered in the network map.
Accounts provide you with a way to represent external identities which were earlier represented at the application level. However, they are not Corda identities. So what are they exactly?
Accounts are just Corda States. So when you create an account in Corda you are actually creating a state, more specifically a state calledAccountInfo.
There are three properties in an account:
- A name given to the account.
- A host for the account, which is a Corda node.
- A uniqueidentifier used to identify the account.
Corda Account library is a CorDapp
As you may have already guessed since an account is a state, it must be part of a CorDapp. The account library ships as a CorDapp, which you can add to your dependencies if you wish to use accounts.
As with any CorDapp, it has two artifacts: one for state and contract, and the other for the flow and services.
Exploring the Account CorDapp
Now that you have an understanding of what accounts are, let’s dig into these artifacts, see what’s in there, and try to understand how accounts work.
Account Contract CorDapp
We will start with the easier one — let’s look at the accounts-contracts CorDapp.
We already took a look at the AccountInfo class earlier. Since every state must be governed by a contract, AccountInfoContract contains some contact rules for the creation of accounts.
Notice that there is just one single command: Create. Currently there is no feature available to update an account once it has been created. However, this feature might be available as a part of future releases.
There is also a schema defined for the account state, thus each account is also stored in a separate database table named accounts in your database.
So that sums up everything from the accounts-contracts CorDapp.
That brings us to the end of this post. To continue exploring and looking into details of the accounts-workflows CorDapp, check out the second part of this blog. Thank you so much for reading.
Want to learn more about building awesome blockchain applications on Corda? Be sure to visit https://corda.net, check out our community page to learn how to connect with other Corda developers, and sign up for one of our newsletters for the latest updates.
— Ashutosh Meher 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 Ashutosh on Twitter here.