Corda Spaceship Auction-Part 1 (Project Setup)

Mabel Oza
InsatiableMinds
Published in
4 min readSep 2, 2020

--

Photo by Terence Burke on Unsplash

We’re going to create a Kotlin Decentralized Corda App, CordDApp that will be an auction for spaceships between different planets. Throughout this tutorial you can always refer back to the Spaceship Corda Github Project (https://github.com/moza88/SpaceshipAuction). This tutorial is broken out into 4 parts, after completing these tutorials you should have Spaceship Auction CorDapp ready to go. Below are the 4 different parts of the tutorial:

  1. Project Setup (this tutorial)
  2. Contracts & States
  3. Workflows
  4. Client (to be published soon…)

Now let’s begin, are you ready? 10, 9, 8, 7, 6, 5, 4, 3, 2, 1… BLAST-OFF!

Every CordaDapp has 3 major components/modules, the contract, workflows, and client.

With all of these components together you can have a working DApp on a Corda Network.

Setting Up Project

Open up your IntelliJ and create a new project called spaceship-auction using a clone of the Kotlin Corda Template project (https://github.com/corda/cordapp-template-kotlin.git)

Adding in Members of your Network

First thing is we’ll add in the members of our network into our deployNodes task in our build.gradle file, the participants in our network are the planets Earth(buyer/seller), Mars(buyer/seller), Jupiter (Auctioneer), and Venus (Notary). The notary is necessary for every DApp, they add in the trust factor and allow planets like Earth and Mars to trade without trusting each other.

Below is what we have for the deployNodes task in our gradle file, first add in the following text then I will explain it.

task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
nodeDefaults {
projectCordapp {
deploy = false
}
cordapp("$corda_release_group:corda-finance-contracts:$corda_release_version")
cordapp("$corda_release_group:corda-finance-workflows:$corda_release_version")
cordapp project(':contracts')
cordapp project(':workflows')
}
node {
name "O=Notary,L=London,C=GB"
notary = [validating : false]
p2pPort 10002
rpcSettings {
address("localhost:10003")
adminAddress("localhost:10043")
}
cordapps.clear()
}
node {
name "O=SpaceX,L=Earth,C=GB"
p2pPort 10005
rpcSettings {
address("localhost:10006")
adminAddress("localhost:10046")
}
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
extraConfig = ['h2Settings.address' : 'localhost:20041']
}
node {
name "O=BlackMirror,L=Mars,C=CA"
p2pPort 10008
rpcSettings {
address("localhost:10009")
adminAddress("localhost:10049")
}
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
extraConfig = ['h2Settings.address' : 'localhost:20042']
}

node {
name "O=RocketMoons,L=Jupiter,C=CH"
p2pPort 10013
rpcSettings {
address("localhost:10014")
adminAddress("localhost:10052")
}
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
extraConfig = ['h2Settings.address' : 'localhost:20045']
}
}

The lines below connect our contract and workflow projects as well as the finance contract and workflow corda modules:

cordapp("$corda_release_group:corda-finance-contracts:$corda_release_version")
cordapp("$corda_release_group:corda-finance-workflows:$corda_release_version")
cordapp project(':contracts')
cordapp project(':workflows')

Each node has the following lines to describe them. The first thing here is the name of our node, it can be anything to describe the node’s identity, this one is called SpaceX, which is Earth. In the rpcSettings the address (10006) is the node’s port you will see when you run it on Corda Shell and admin (10046) is the administrator’s port.

In this case, we are giving each node all the permissions, since different nodes have different roles they should have different roles like the auctioneer shouldn’t have permission to bid. We’ll fine-tune the permissions in the future.

The extra configuration here is the address to the h2 database, this will allow us to use an h2 in-memory database to access the data.

node {
name "O=SpaceX,L=Earth,C=GB"
p2pPort 10005
rpcSettings {
address("localhost:10006")
adminAddress("localhost:10046")
}
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
extraConfig = ['h2Settings.address' : 'localhost:20041']
}

Now we are going configure Quasar, Quasar is helpful in handling async machines.

Quasar allows Corda developers to write simple, straight-line blocking code and have it transformed into highly scalable asynchronous state machines that checkpoint their state to disk as messages fly around and the workflow progresses.

task installQuasar(type: Copy) {
destinationDir rootProject.file("lib")
from(configurations.quasar) {
rename 'quasar-core(.*).jar', 'quasar.jar'
}
}

Setting up the Project’s Configuration

Now fill in the rest of the details in the build.gradle file by copying the following in the root build.gradle file, you will have errors because you haven’t yet defined the version. We state all the versions in another file constants.properties (see the 2nd and 3rd line).

State all your version numbers referenced in your build.gradle file by creating the constants.properties file in the root directory and add in the following lines:

cordaReleaseGroup=net.corda
cordaCoreReleaseGroup=net.corda
cordaVersion=4.4
cordaCoreVersion=4.4
gradlePluginsVersion=5.0.4
kotlinVersion=1.3.70
junitVersion=4.12
quasarVersion=0.7.10
log4jVersion =2.11.2
platformVersion=5
slf4jVersion=1.7.25
nettyVersion=4.1.22.Final

Provide your dependency repository by creating the repository.gradle file in the root directory and add in the following lines:

repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda' }
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
}

Now for the last piece, we need to glue all the modules together in our settings.gradle file with the following lines:

include 'workflows'
include 'contracts'
include 'clients'

Now our overall project is set up, let’s get to the fun part, our contracts, workflow, and client modules. Move over to Part 2 to start working on the contract module and get into states and contracts in Corda.

--

--

Mabel Oza
InsatiableMinds

Making the financial world more secure, accessible, and transparent.