Test Catenis Flow Connectivity To the Catenis APIs
After you have installed Catenis Flow on Node-RED and configured our first virtual device we will test that we properly configured connectivity by logging a message on to a Bitcoin transaction and have it logged to the blockchain. To do this, let’s start by creating our first flow by using the Catenis Flow ”Log Message” Node.
- Drag and drop from the Common category the Input “inject” node from the left pallet menu (this node once dropped will read “timestamp”)
- Drag and drop from the Catenis category the “Log Message Node” from the left Pallet menu on to the right of the “inject” node
- Drag and drop from the Common category the Output “ Debug Node” from the left pallet menu on to the right of the “Log message node” from the previous step (this node once dropped will read “msg.payload)
Now, let’s wire the nodes together so each node knows where to take input and where to inject output. Nodes are wired together by pressing the left mouse button on a node’s port (the gray square box that becomes orange color), dragging to the destination node and releasing the mouse button. To do this:
- The inject node (left-most in the color blue) should be connected to the log node (purple one in the middle) by clicking the gray square box on its right side and dragging the mouse to the gray square box on the left side of the log node.
- The log node should be wired to the debug output node in the same manner (dragging the gray square box on the right hand side of the log node and connecting it to the gray square box on the left side of the debug node.
Let’s configure each node so we can test logging a “Hello World” message on the blockchain
First, we are going to enter a payload message for the inject node (i.e the data it will inject into a connected node).
- Double click the inject node to bring up the properties panel for that node. Click on the drop-down menu next to the “Payload” property, which should be set to “timestamp” by default, and change it to “string”. This enables the node to inject the text you enter in the data field.
- In this case, we will enter the sample text “Hello World”. Do not alter any of the other properties for now.
- Click Done
Next, we will set up the log message node and assign it to the proper Virtual Device (Bitcoin Connector) that you should have already created and configured. To do this:
- Double click on the log message node (purple one in the middle).
- Uncheck the Encrypt checkbox so we can see the message directly on the blockchain using a block explorer.
- Uncheck the off-chain message so a bitcoin transaction is created in real-time for testing. Note: When building an application you should always use off-chain messages. Standard messages incur higher fees, cost more Catenis credits and create unneeded bitcoin transactions.
- Click the drop-down menu of the “Device” property of the node
- Assign the device to what you created in the previous steps (in this case we named our Virtual Device “Bitcoin Connector”).
- Click the “Done” button.
Now, we can test if your flow successfully logs the Hello World message to the blockchain. To do this we must deploy the flow and then inject the message using the log message node. Do the following:
- Click the red button to the top right-hand side of the workspace that says “Deploy”. You should see a pop-up notifying you the flow was successfully deployed.
- Click the gray square box to the left of the inject node (which contains the Hello World string) to pass the “Hello World” message from the inject node to the log message node and through the flow. If successful, the message ID should print to the debug sidebar on the right.
Now, we are going to retrieve from the blockchain the location of the message we just logged. To do this we will inject the message ID that was returned from the previous step into the “retrieve container” node. This “retrieve cntainer node” will return the “Bitcoin Transaction ID” and the location of the content of the message of this message if successful. General steps are as follows:
- Insert from the common category a new “inject” node, from the Catenis Flow category a “retrieve message container” node, and from the common category a “debug” node into the workspace side by side.
- Set the parameter of the properties of the “inject” node’s payload field to “string” and enter the message ID generated that was returned when you logged the message (the message ID will be displayed at the right sidebar. Click “copy value” icon and paste it into the payload area)
- Configure the device parameter of the “retrieve message container” node to the same device used in the “log message” node.
- Wire the inject node to the “retrieve message container” and the “retrieve message container” node to the debug output node.
- Click the “Deploy” button and then click the button to the left of the inject node to send the message payload to Catenis and the bitcoin transaction.
Here, we place the “inject node”, the “retrieve message container” node, and a “debug node” onto the workspace
Next, we change the payload of the inject node to the message ID generated and returned to us when we sent the “Hello World” message to the bitcoin blockchain. We need to copy the messageId that is displayed on the debug pane. Then we will place that message ID in the debug node.
Now we set the Catenis Flow “retrieve message container” node to use the previously configured virtual device (called a Node-RED configuration node). This should be the same virtual device configuration that was used when we configured the log message flow. In our case, we called it the “Bitcoin Connector”.
Finally, we wire the three nodes together.
Now let’s deploy the flow.
- Click the red “Deploy” button on the top right-hand side of the application.
- Switch to the Debug Panel on the right sidebar (debug icon)
- Click the inject button (small gray square on the left of the inject node) to inject the message ID into the “retrieve message container” node.
- You should see a JSON object output on the debug sidebar with a blockchain object containing name-value pairs. To see its content click to expand on the“object arrow” and once again click on the “blockchain arrow”. It will expand and display a “txid” and “isConfirmed” name-value pairs. The txid is the Bitcoin transaction ID and the location of where the logged message is stored on the Bitcoin blockchain.
You can verify that your Bitcoin transaction has been successfully logged on the Bitcoin blockchain by using a testnet block explorer. For this example we will use the Bitaps testnet block explorer located at https://tbtc.bitaps.com
Entering your Bitcoin transaction ID in the search field and pressing the enter button on your keyboard should display the “Hello World” message in the “Data Text” section (this is the Bitcoin transactions OPT_RETURN, also known as Null Data).