Corda R3 — Getting everything to work together
Tags: Cordapp, Distributed Ledgers, Corda, Corda R3, Kotlin

How to run commands?

Running commands on the node shell is pretty straightforward if you have experience with terminal:

For instance we can run flow list command to list all available flows on that node. As we can see all the flows we created previously are listed and are available to be executed on demand.

Creating Wallets and Accounts

Let’s create a new wallet for each of our nodes, A and B. We can do that by running

> flow start com.marcus.flows.CreateWalletFlow accountCurrencies [“EUR”]

let’s destruct this command to be easy to understand.

flow start — is the corda shell command to initiate a new flow

— is the corda shell command to initiate a new flow com.marcus.flows.CreateWalletFlow — is the flow we want to initiate

is the flow we want to initiate accountCurrencies [“EUR”] — we know that CreateWalletFlow requires arguments to be passed to it. In this case we passing a set of currencies [“EUR”] on accountCurrencies argument.

CreateWalletFlow returns a WalletState as a result, which we can see being printed after running the flow

Let’s verify that we can add a new currency to our wallet by running:

> flow start com.marcus.flows.CreateAccountFlow currency: “USD”

As expected there is a new AccountState created for our wallet.

We can quickly verify that our WalletState now contains two accounts

> run vaultQuery contractStateType: com.marcus.states.AccountState

As expected we can see that in our node we have two AccountState — one for EUR and USD — we can also notice that they both belong to the same WalletState as we can see from the walletStateId

walletStateId:

externalId: null

id: "efff8b5b-fe98-4f04-a231-094cdc0281c6"

If we query the vault for the wallet state on the same shell, we will verify that the only wallet in that vault has the above id

> run vaultQuery contractStateType: com.marcus.states.WalletState

Making our first transfer

To make a transfer is very simple we just need to call MakeTransferflow

> flow start com.marcus.flows.MakeTransferFlow destination: "O=PartyB, L=New York, C=US", amount: 1 EUR

In this case we are transferring 1 Euro to party B, for obvious reasons, this command should be ran on Party A shell — Party B cannot transfer to itself.

We can see in the result that this transfer was a success. 🚀 and if we want to check the transfer states we can use

> run vaultQuery contractStateType: com.marcus.states.TransferState

In this state we can see that both participants are listed under participants, which means that this transfer state is also persisted into Party B vault.

If we want to sell all movements for a certain node, we can run

> run vaultQuery contractStateType: com.marcus.states.MovementState

And we can see that there is a movement associated with the previous transfer, and that this is a DEBIT movement — meaning money left this account.

If we execute the same command on PartyB shell, we expect to see a similar movement but with status CREDIT.

Requesting a transfer

Requesting a transfer is very similar to making a transfer in the first place, but with one more step.

Let’s start by requesting 10 Euros from Party A, in this case the following command should be executed on Party B’s shell

> flow start com.marcus.flows.RequestTransferFlow origin: “O=PartyA, L=London, C=GB”, amount: 10 EUR

Ff we query Party A’s vault for Transfer states we will find that there is a new TransferState created with status Requested, which Party A can then execute and make the transfer to Party B.

To execute the transfer Party A can execute the following command:

> flow start com.marcus.flows.ExecuteRequestedTransferFlow linearId: “6e6e763f-d2a3-49c6-8eae-713a2c42b55d”

We need to specify which requested transfer are we executing, and for that we use the transfer linearId, in this 6e6e763f-d2a3–49c6–8eae-713a2c42b55d.

Finally, you may find all code in this series on my github account, feel free to download it and change as much as you want.