Let’s get you on a blockchain
It won’t take more than five minutes.
Editors note: this is the piece from the R3 content plan on the wiki for the following portion of the developer story.
Getting start with Corda. (Set up → debugging set up → clone test app → run test app) No development yet. This blog is to get developer hooked to really see this Corda stuff works.
Blockchain can seem more complicated than it really is. I’m going to just give you a quick guided tour of how to get a Corda distributed application (or CorDapp) running so you can get started building something from there.
We’re going to go through a small tour of how to run a CorDapp on your machine and get some transactions going so you can go from here to building your ideas using blockchain.
We’re going to build off of a basic code example called the Yo CorDapp. You can find a copy of it here.
The Yo CorDapp is essentially a tool to share a single entity, a yo, from one node to another.
We’ll setup two Corda nodes that simply run a flow to share some information in the form of a transaction
In the case of the Yo CorDapp, a “Yo” is simply an object that contains the string yo, along with a recipient. As always when we’re going to send something from one machine to another, we have to specify a recipient, and that’s the other piece of the yo state.
Here’s how we get this working
- download the code
- run the nodes
- perform a transaction
We’ll start by just downloading the Corda samples github repo and opening the yo-cordapp folder.
davidawad@boron ~/Desktop> git clone https://github.com/corda/samples-java/
Cloning into ‘samples-java’…
remote: Enumerating objects: 405, done.
remote: Counting objects: 100% (405/405), done.
remote: Compressing objects: 100% (211/211), done.
Receiving objects: 14% (527/3590), 4.06 MiB | 480.00 KiB/sdavidawad@boron ~/Desktop> cd Basic/yo-cordapp/
When that’s done, we’re just going to build the nodes, and run the nodes.
If you’re curious; these tasks that you’re running with ./gradlew are outlined in build.gradle.
davidawad@boron ~/Desktop>
davidawad@boron ~/Desktop> ./gradlew deployNodes
davidawad@boron ~/D/s/B/yo-cordapp>master> ./build/nodes/runnodes
Now when you run that runnodes command you’ll get a Corda shell running.
Open up the shell on PartyA, and we’ll run our flow.
Tue Jul 21 16:07:56 EDT 2020>>> flow list
net.corda.core.flows.ContractUpgradeFlow$Authorise
net.corda.core.flows.ContractUpgradeFlow$Deauthorise
net.corda.core.flows.ContractUpgradeFlow$Initiate
net.corda.examples.yo.flows.YoFlow
And it is from here that we can run our flow and see the transaction happen before us.
Tue Jul 21 16:22:24 EDT 2020>>> flow start YoFlow target: PartyB✅ Starting
✅ Creating a new Yo!
✅ Signing the Yo!
✅ Verifying the Yo!
✅ Sending the Yo!
Requesting signature by notary service
Requesting signature by Notary service
Validating response from Notary service
➡️ Broadcasting transaction to participants
Done
Now once you’ve done this, you can jump onto the other node and actually run a vault query to see how many yo states that the Corda node has received.
Tue Jul 21 16:07:57 EDT 2020>>> run vaultQuery contractStateType: net.corda.examples.yo.states.YoState
states:
- state:
data: !<net.corda.examples.yo.states.YoState>
origin: "O=PartyA, L=London, C=GB"
target: "O=PartyB, L=New York, C=US"
yo: "Yo!"
contract: "net.corda.examples.yo.contracts.YoContract"
notary: "O=Notary, L=London, C=GB"
encumbrance: null
constraint: ! [ . . . ] status: "UNCONSUMED"
notary: "O=Notary, L=London, C=GB"
lockId: null
lockUpdateTime: null
relevancyStatus: "RELEVANT"
constraintInfo:
constraint:
key: "aSq9DsNNvGhYxYyqA9wd2eduEAZ5AXWgJTbTEw3G5d2maAq8vtLE4kZHgCs5jcB1N31cx1hpsLeqG2ngSysVHqcXhbNts6SkRWDaV7xNcr6MtcbufGUchxredBb6"
totalStatesAvailable: -1
stateTypes: "UNCONSUMED"
otherResults: []
And there you have it! A blockchain in the palm of your hands. There are many directions you can take it from here, we’ll leave it to you!
If you’re more curious about how to really build out some these abstractions; I’d highly recommend our documentation on the Corda Core concepts, States, Contracts, and Flows.
Want to learn more about building awesome blockchain applications on Corda? Be sure to visit 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.
— David Awad 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 David on Twitter here.