Corda CLI – solve multiple problems using one solution

September 28, 2021
Corda CLI_ Diagram
Corda CLI Cmd Line Tool performing these tasks — Configure the docker network, start the nodes inside docker containers, deploy the CPB to the nodes, inspect CPK, CPB contents

Configuring, managing and deploying a Corda network consists of a number of steps. To make this process easier and more efficient, the R3 team has built an in-house command-line tool for managing the entire life cycle of a Corda network, right from its creation to its termination. After using this tool for a good amount of time internally, we have decided to ship it to our community as well.

One key aspect of deploying a network using Corda CLI is that this is a one-time effort. Each time you make any change to your CorDapp, you don’t have to redeploy the network, unlike the deployNodes task or DriverDSL from the previous versions. This is good for rapid development and testing as now you don’t have to wait for the network to be created and started every time you make any changes in your CorDapp.

In this blog, we will take a deep dive into how you can use the Corda CLI tool for network setup, and CPK/CPB/Jar file inspection. For this blog, I will use the Solar system CorDapp as an example.

To follow along, make sure you have downloaded and installed the Corda CLI Dev Preview artifact.

Network Setup

1. Configure Network Type

Using Corda CLI we target two types of network deployments:

sneha.damle@21IND-MAC2M4MD6N c5-cordapp-template-kotlin % corda-cli network config –help
Configure a node or network
Usage: corda-cli network configure <deploymentType> <networkName>
<deploymentType>   The type of the deployment values: docker-compose
<networkName>      The name of the network
  1. docker-compose

Corda CLI uses the docker-compose tool to deploy local docker containers using a docker-compose.yaml file. This is useful for setting up local dev environments and to quickly test your applications. This network type is available as a part of the Corda 5 Dev Preview.

  1. kubernetes

This is the type of network that will be ideal for production deployments, for example  on cloud systems. This is not available for Dev Preview, but you will see more information on this in upcoming releases.

corda-cli network config docker-compose solar-system

The above command configures and creates a yaml file in the ~/.corda folder. This file is similar to the “profile” which is created in azure/aws. This will be further extended to add authentication user profiles to this file. But for now, the config command specifies the type of network won’t be deployed.

sneha.damle@21IND-MAC2M4MD6N .corda % cat network.yaml
solar-system: docker-compose

2. List all configured networks

You can use the below command to list all the available configured networks:

corda-cli network list -n solar-system 
Available networks:
docker-compose
– solar-system
– test-network
  1. Deploy and start the network

Once configured, you can now deploy and start the network by providing a reference to a YAML file containing node config. The CLI tool also pulls the corda-dev image containing the network bootstrapper image. The network bootstrapper will be used by the CLI tool to generate the necessary artifacts like the keys, node configs, member node-info’s etc. Please note that these generated artifacts, or rather the use of network bootstrapper to create the network are suitable for rapid development and testing environments. There will be significant changes to this in future releases.

corda-cli network deploy -n solar-system -f c5cordapp-template.yaml | docker-compose -f – up
  1. Check the network status

The below command can be used to check the status of the network:

corda-cli network status -n solar-system

5. Terminate the network

Use the below command to terminate the network. This deletes all the docker containers and thus all the deployed nodes:

corda-cli network terminate -n solar-system -ry

Node Interaction

The Corda CLI tool can be used to deploy CorDapps to individual nodes. It can also be used to inspect the contents of the deployed CPK and CPB files or for that matter any jar file. (Take a look at the series of steps required to create a CPK, CPB file here).

1. Deploy CorDapps onto Nodes

Once the node is up, we can run the below command to load the CorDapp i.e. the CPB file containing contract and flow CPKs to individual nodes.

<bcorda-cli package install -n solar-system result.cpb</b

You can load CorDapps to individual nodes as well. This is good for scenarios where you want to test how two nodes having different versions of the same CorDapp talk to each other. Use the below command to install a CorDapp on a specific node:

corda-cli package install -n solar-system -m PartyA result.cpb

2. View contents of CPK/CPB/Jar file

Use the below command to inspect the contents of any CPB file:

corda-cli package list result.cpb

result.cpb:install.json

result.cpb:contracts-1.0-SNAPSHOT-cordapp.cpk

result.cpb:contracts-1.0-SNAPSHOT-cordapp.cpk:META-INF/MANIFEST.MF

result.cpb:contracts-1.0-SNAPSHOT-cordapp.cpk:META-INF/CORDAPP.SF

result.cpb:contracts-1.0-SNAPSHOT-cordapp.cpk:META-INF/CORDAPP.EC

result.cpb:contracts-1.0-SNAPSHOT-cordapp.cpk:META-INF/

result.cpb:contracts-1.0-SNAPSHOT-cordapp.cpk:contracts-1.0-SNAPSHOT.jar

…….

3. View all recursive dependencies of a CPB file

You can take a look at all the dependencies of all the CPKs recursively within a particular CPB using the deps command:

corda-cli package deps result.cpb

result.cpb:contracts-1.0-SNAPSHOT-cordapp.cpk:contracts-1.0-SNAPSHOT.jar:META-INF/CPKDependencies:

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>

<cpkDependencies xmlns=”urn:corda-cpk”/>

result.cpb:contracts-1.0-SNAPSHOT-cordapp.cpk:contracts-1.0-SNAPSHOT.jar:META-INF/DependencyConstraints:

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>

<dependencyConstraints xmlns=”urn:corda-cpk”>

<dependencyConstraint>

<fileName>gson-2.8.6.jar</fileName>

<hash algorithm=”SHA-256″>yPtIOQVNKAswM/gA0fWpfeLwKOuLoutFitKH5Tbz8l8=</hash>

</dependencyConstraint>

</dependencyConstraints>

result.cpb:workflows-1.0-SNAPSHOT-cordapp.cpk:workflows-1.0-SNAPSHOT.jar:META-INF/CPKDependencies:

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>

<cpkDependencies xmlns=”urn:corda-cpk”>

<cpkDependency>

<name>net.corda.flows</name>

<version>5.0.0.DevPreview-RC07</version>

<type>corda-api</type>

<signers>

<signer algorithm=”SHA-256″>qlnYKfLKj931q+pA2BX5N+PlTlcrZbk7XCFq5llOfWs=</signer>

</signers>

</cpkDependency>

<cpkDependency>

<name>com.r3.devrel.contracts</name>

<version>1.0.0.SNAPSHOT</version>

<signers>

<signer algorithm=”SHA-256″>qlnYKfLKj931q+pA2BX5N+PlTlcrZbk7XCFq5llOfWs=</signer>

</signers>

</cpkDependency>

</cpkDependencies>

result.cpb:workflows-1.0-SNAPSHOT-cordapp.cpk:workflows-1.0-SNAPSHOT.jar:META-INF/DependencyConstraints:

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>

<dependencyConstraints xmlns=”urn:corda-cpk”/>

Further Reading

For more information on Corda, the CLI tool visits the docs site.

This blog talks about the initial setup required to run your Corda 5 Cordapp.

This blog talks about the Corda 5 packaging model.

This blog talks about how to run your first CorDapp sample.


— Sneha Damle 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, Corda Enterprise, a commercial version of Corda for enterprise usage, a confidential computing platform.

Follow Sneha on LinkedIn here.

Share: