CordaCon 2019 Highlights: Truffle’s Corda Flavored Ganache

Adel Rustum
B9lab blog
Published in
7 min readJan 8, 2020

--

Making this banner with Microsoft Paint took longer than writing this article.

This blog is part of a series of short articles highlighting the new and exciting things that I learned about in CordaCon 2019 which was held in London.

The series will talk about:

  1. VSCode-Corda Plugin for Visual Studio Code.
  2. Braid Server and OpenAPI Generator for Corda Client API’s.
  3. Web3j Corda SDK.
  4. Truffle’s Corda Flavored Ganache.
  5. R3’s Accounts library.
  6. R3’s Tokens SDK.

Truffle’s Corda Flavored Ganache

Truffle suite plays a huge role in the Ethereum development world. With one-word commands you can create an empty Ethereum project, compile it, test it, and migrate it to your network of choice. You can use the JavaScript model of your Ethereum contracts (i.e. truffle-contract) inside your NodeJS apps to interact with them. Truffle also has the concept of boxes where you can download a box, unbox it, and it will give you the full files structure that is required for a certain flavor (e.g. drizzle, react, webpack).

Another important product from Truffle is Ganache which (again with one word) can create a private Ethereum network with 10 unlocked accounts each with 100 Ethers; making it easy to run quick deployments and tests instead of building your own private network (which requires writing a genesis file, start the network, create accounts, start mining to supply them with Ether, unlock them before using them, etc…).

Naturally I was very excited when I heard the guys from Truffle announcing in CordaCon that they will be building something similar for Corda.

Right before Christmas I received an email that the beta version has been released; so I decided to download it and give it a spin, below are my findings.

Installing Ganache

  • It’s up to you to enable or disable Analytics (at the bottom of the window).

Quick Start

  • Click continue and switch to Quickstart Corda:
  • It will download PostgreSQL, JRE, and Corda Network Bootstrapper; run the bootstrapper, copy the CorDapps, then start the Corda nodes:
  • Let’s click on the Logs tab and choose PartyA:
  • From the above screen, you’ll see that the quick-start setup is running Corda 4.3; which is great!
  • Back to the Nodes tab; select PartyA, lots of useful information there. As you can see, we don’t have any CorDapps installed yet:
  • Let’s install some CorDapps on our nodes.
  • Clone the samples repository: git clone https://github.com/corda/samples.git
  • Open the IOU example (i.e. cordapp-example project) with IntelliJ and let Gradle do its work.
  • Browse to the IOU example: cd samples/cordapp-example
  • Build the nodes: ./gradlew deployNodes
  • Inside Ganache, click on the gears icon (i.e. settings icon) in the top right corner:
  • Under WORKSPACE tab, click on Add CorDapp:
  • Browse to the cordapps folder of PartyA. IOU example comes with Java and Kotlin versions; so you’ll find the build folder under the workflows-java or workflows-kotlin folder. I chose Java, so the cordapps folder is under: path-to-cordapp-example/workflows-java/build/nodes/PartyA/cordapps:
  • You can’t add both jar files at the same time, you have to repeat the above step twice (i.e. once for contracts and once for workflows).
  • Now we need to restart the nodes; click on Save And Restart:
  • If you open the Nodes tab and click on PartyA, you’ll see the 2 CorDapps installed:
  • As you can see, the CorDapps got installed on all 3 nodes.
  • Now that all nodes are running and the IOU CorDapps are installed; let’s try to create an IOU.
  • To access a node terminal, you can ssh to it or use the standalone shell; more on that here: https://docs.corda.net/shell.html
  • For the sake of simplicity, I will not access the node terminal then run the flow; instead, the IOU example comes with a clients module (i.e. webserver) that serves an API to create an IOU.
  • Open build.gradle under the clients module, it has the Gradle task that starts the webserver. As you can see we need to update the RPC port, username, and password:
  • Inside Ganache, open PartyA under the Logs tab. There we can find the path where the node was built which will lead us to the node.conf file:
  • Open node.conf file that you find under that path; there you will find the RPC port, username, and password for PartyA node:
  • Update the Gradle task with those values and click on Import Changes when prompted:
  • Now we’re ready to run the webserver; open a terminal and browse to cordapp-example: cd path-to-cordapp-example
  • Start the webserver: ./gradlew runPartyAServer
  • Open a new terminal and create an IOU with this command (CURL must be installed beforehand): curl -i -X POST 'http://localhost:50005/api/example/create-iou?iouValue=12&partyName=O=Party%20C,L=New%20York,C=US' -H 'Content-Type: application/x-www-form-urlencoded'
  • The command will return the transaction hash:
  • Back to Ganache, click on Transactions tab; you’ll see one transaction, click on it. Wow, so much information there!

New Workspace

In the first section of this article, we used the quick-start approach; now let’s use the advanced method (i.e. New Workspace):

  • You’ll notice that it’s defaulted with 3 nodes and a notary (same setup as quick-start), and it has the same CorDapps that we installed previously.
  • You can click on any tab and edit the information, for instance you can add/remove nodes or update their port numbers:

I guess for more advanced setup, you’d have to first save the workspace (which builds the nodes and starts them); then you can modify the generated node.conf files (e.g. add RPC users, etc…).

Conclusion

As you can see, Ganache has some really cool features. With a very intuitive GUI you can build a Corda network, install CorDapps on its nodes, then inspect the resulting transactions with great detail, and this is just the beta version (i.e. the beginning).

I’m looking forward to see how this product will evolve and what surprises the Truffle team will present us with in the next CordaCon.

— — — — — — — — — — — -

B9lab Academy has partnered with R3’s Corda to create free online learning materials. It can take you from zero blockchain knowledge to creating cordapps that work with cash, debt and other contracts, and facilitates flexible, potentially complex settlement agreements across multiple currencies and instruments.

You can get additional support from our expert instructors for 3 months to help you succeed through all stages of the training.

— — — — — — — —

Other blogs in the series:

  1. VSCode-Corda Plugin for Visual Studio Code.
  2. Braid Server and OpenAPI Generator for Corda Client API’s.
  3. Web3j Corda SDK.
  4. R3’s Accounts library.
  5. R3’s Tokens SDK.

--

--