Use Node-RED to execute a sample application

This article describes how you can use the TYMLEZ development tools to run the track and trace sample application as a Node-RED flow.

Video

The video below shows you how can use the CLI and the Node-RED UI to execute the track and trace sample application as a Node-RED flow.

NodeRed_CLIUI

Introduction

In addition to executing the track and trace sample applications via the command line, you can also execute it as a Node-RED sample.

To begin, you will require the location of the Node-RED flow for the track and trace sample application; it can be found in the repository ng-rt-digitalasset-sdk-samples.

Prerequisites

  • Note that the TBSP development tools are required to execute the Node-RED flow.
  • Ensure that the admin user has already logged in with the required JWT token.
  • Ensure that the node-RED URL in the .tymlez/config.json has already been set:
tymlez-dev config setNodeRedUrl --nodeRedUrl=<YOUR_IP_ADDRESS> --protocol=<http OR https>

Execution via command line 

Obtain the access token for the admin user:

tymlez-dev nodeRed getAccessToken --context=<YOUR_CONTEXT_HERE> --username=admin --password=<GENERATED_PASSWORD_HERE>

You should see the following output:

[INFO] nodeRedCommands.getAccessToken - access token: true

You now have been authenticated to the platform.

Import the flow to your TBSP on Google Cloud Platform instance by specifying the location of the Node-RED flow and giving the flow a name:

tymlez-dev nodeRed uploadFlow --context=<YOUR_CONTEXT_HERE> --filePath=<PATH TO trackAndTrace.json> --flowName=Track

You should see the following output:

[INFO] nodeRedCommands.uploadFlow - flow deployed: true

After importing the flow, execute it:

tymlez-dev nodeRed runFlow --context=<YOUR_CONTEXT_HERE> --flowName=<YOUR_FLOW_NAME_HERE>

The Node-RED flow is then executed.

[INFO] nodeRedCommands.runFlow - Flow executed successfully !!

[INFO] nodeRedCommands.runFlow -

{ 'Manufacturer public Key': '2qw8uHUgr72R8NC3QXs9yy5XmDXD5ATugkv566WmyrRB',

  'Alice public Key': 'GXx53nnU6aTv6K46V9SGktN9GN5Vq5RrPFGtuZgfPo76',

  'Bob public Key': '5BnCuYx1d2EthchHQtHqPGAHnT3oq1576UF2MBByS56d',

  'Tx id of the car asset owned by Manufacturer':

   'efcce946a2700f0a04239929ef6e9450ed5d2d2d9c352b5298d5a08a4576937e',

  'Tx id of the transfer of car asset from manufcturer to alice':

   'eabbaaa5abb84eaf589609962c91690ffff41da81a8006405a4b20489ce23aa1',

  'Tx id of the transfer of car asset from alice to bob':

   'e837fd2f59d7e98bc4f4b8afcd6b153c2ac7114ff2df5a95e8640c52af728263',

  'The current owner of the car asset': '5BnCuYx1d2EthchHQtHqPGAHnT3oq1576UF2MBByS56d',

  'Asset history of car asset':

   [ { txId:

        'efcce946a2700f0a04239929ef6e9450ed5d2d2d9c352b5298d5a08a4576937e',

       from: [Array],

       to: [Array],

       amount: 1,

       timestamp: 1589284061746 },

     { txId:

        'eabbaaa5abb84eaf589609962c91690ffff41da81a8006405a4b20489ce23aa1',

       from: [Array],

       to: [Array],

       amount: 1,

       timestamp: 1589284062047 },

     { txId:

        'e837fd2f59d7e98bc4f4b8afcd6b153c2ac7114ff2df5a95e8640c52af728263',

       from: [Array],

       to: [Array],

       amount: 1,

       timestamp: 1589284062271 } ],

  'Transaction history of the manufacturer':

   [ { txId:

        'efcce946a2700f0a04239929ef6e9450ed5d2d2d9c352b5298d5a08a4576937e',

       direction: 'create',

       from: [Array],

       to: [Array],

       amount: 1,

       assetType: 'tendermint_blob',

       timestamp: 1589284061746 },

     { txId:

        'eabbaaa5abb84eaf589609962c91690ffff41da81a8006405a4b20489ce23aa1',

       direction: 'out',

       from: [Array],

       to: [Array],

       amount: 1,

       assetType: 'tendermint_blob',

       timestamp: 1589284062047 } ],

  'Transaction history of the alice':

   [ { txId:

        'eabbaaa5abb84eaf589609962c91690ffff41da81a8006405a4b20489ce23aa1',

       direction: 'in',

       from: [Array],

       to: [Array],

       amount: 1,

       assetType: 'tendermint_blob',

       timestamp: 1589284062047 },

     { txId:

        'e837fd2f59d7e98bc4f4b8afcd6b153c2ac7114ff2df5a95e8640c52af728263',

       direction: 'out',

       from: [Array],

       to: [Array],

       amount: 1,

       assetType: 'tendermint_blob',

       timestamp: 1589284062271 } ],

  'Transaction history of the bob':

   [ { txId:

        'e837fd2f59d7e98bc4f4b8afcd6b153c2ac7114ff2df5a95e8640c52af728263',

       direction: 'in',

       from: [Array],

       to: [Array],

       amount: 1,

       assetType: 'tendermint_blob',

       timestamp: 1589284062271 } ] }


Execution via the Node-RED UI

In addition to using the CLI, you can also import the track and trace sample application flow using the Node-RED UI.

First, navigate to the repository containing the Digital Asset SDK samples.

In this repo, navigate to Examples > nodeRedFlow > trackAndTrace.json.

Copy the contents of the json file.

In the Node-RED UI, create a new flow called Track:

Screen Shot 2020-05-18 at 3.42.06 PM

Click on the three horizontal bars on the right-hand side, and select the Import button:

Screen Shot 2020-05-25 at 2.24.03 PM

Select the Import from Clipboard option:

Screen Shot 2020-05-25 at 2.29.45 PM

In your Docker SDK container, navigate to the repo ng-rt-digitalAsset-sdk-samples > examples > nodeRedFlow > trackAndtrace.json. 

Copy this JSON code.

In the following screen, paste the json code from the previous step and import to the current flow:

Screen Shot 2020-05-25 at 2.45.00 PM

Deploy the flow with the Deploy button in the right hand corner above:

Screen Shot 2020-05-19 at 5.00.51 PM

After importing the flow, execute it:

tymlez-dev nodeRed runFlow --context=<YOUR_CONTEXT_HERE> --flowName=<YOUR_FLOW_NAME_HERE>

Go back