Visual Studio Code
A bespoke Corda plugin for the popular IDE
In this chapter you step aside from code and focus on tooling. Specifically, Microsoft's free Visual Studio Code (VSC) and a bespoke Corda plugin.
So far in the course, when you wanted to manually test your flows, like you did with the IOU CorDapp, you had to do all the hard labor of building your nodes, deploying them, and starting them. That's a lot of mechanical actions. So R3 built a plugin for the Visual Studio Code IDE that elevates those tasks to simple one-click commands.
What you are going to do is:
- Get set up.
- Use the cordapp-example.
- Deploy nodes.
- Run nodes.
First, download VSC from https://code.visualstudio.com/, then open it.
Second, you need to install the plugin. So:
- Click on the Extensions icon to the left.
- Search for "corda" when prompted.
- Click on the green Install button:
Have a read through its README file as the extension is being installed. You will explore each command one by one, while running them against the cordapp-example project.
That's all with regard to setup.
If you have not done so yet, clone the samples repository in your preferred location. The samples repository has a sub-folder named
cordapp-example. This is the project to use in this exercise. Click on File -> Open Folder and choose
Wait until Gradle is done downloading all dependencies and building your project, if that’s the first time you open this project.
The plugin will identify this project as a Corda project and display this finding in the status bar:
VSC's command palette is where you can find all available actions, not limited to the hard-coded ones you can find in the menus. At any time, you can open the command palette with Ctrl + Shift + P or Cmd + Shift + P. So open it now and start typing corda to see all the available commands related to Corda:
Give the tests a spin. Select Corda Run Tests:
With the tests done, deploy the nodes. This action will create a separate folder for each node that has been defined inside the
deployNodes task of
build.gradle file under
By the way,
cordapp-example is a special case in that it has the modules written in both Java and Kotlin for demonstration purposes. You do not need to code your project in both languages. That's why you'll notice in the terminal that the command is building both versions.
From the command palette, pick Corda DeployNodes:
With the nodes deployed, run them. Pick Corda Run Nodes and wait for all the nodes to start. Notice how you have a dropdown list that shows all of your nodes. This is much more pleasant than with the multiple terminal windows we saw in a previous module!
Don't forget to stop your nodes, including the notary, properly by typing
bye inside each terminal. Otherwise your nodes might fail to start in subsequent attempts
But, for now, keep them running so as to try the rest of the plugin's commands.
With the nodes running, it is time to start one of the flows. Before you do, do you remember how you used
>>> run vaultTrack on a node to see a new transaction being saved in real time? The Corda plugin has the same concept here, just more pleasant.
From the command palette, choose Corda Show Transaction Explorer. It takes a bit of time to start. When it's ready, select PartyA from the dropdown list and you’ll see some details about your node, plus another dropdown that lists the flows that the node can run:
Choose the first flow com.example.flow.ExampleFlow$Initiator. Notice how it lets you choose a specific constructor if your flow has more than one constructor. The window now displays the required input parameters, and not only that, it also provides autocompletion on values.
Input an iouValue and select PartyB. Time to run the flow. Click on RUN FLOW. You should receive 2 pop-up notifications: "flow started", and "flow finished".
When done, the transaction explorer window shows the resulting transaction. Click on its arrow to expand its details:
Open PartyB in the transaction explorer and see the same transaction. Indeed, both
lender are the participants of the IOU state:
Now let’s run the same flow again but issue an IOU from PartyA to PartyC. Select PartyA again:
You can also confirm that PartyC only knows of the second transaction.
Time to explore another feature of the plugin. In the command palette, choose Corda Show Vault Query View. Notice how the Query Builder gives you many options to filter your result set. Of note, it also provides you with auto complete on the StateRef field!
As you can see, the Visual Studio Code Corda plugin makes it easier to spin your nodes quickly. As well as being useful for you, the developer, it can be very useful for the QA team. They may not necessarily know how to start nodes and run commands from the terminal. The GUIs of the Transaction Explorer and Vault Query View make the process very simple.
In the following modules, you will test your flows by hand too using this plugin, and not just with unit tests.