This page provides a step-by-step tutorial to integrate a blockchain SmartApp with xooa's blockchain-as-a-service (BaaS).
The repository used in this example is https://github.com/Xooa/smartThings-xooa
There are two components in this repo, the blockchain chaincode (henceforth chaincode) and the SmartThings SmartApp. The chaincode is deployed via the xooa console; the SmartApp via the SmartThings IDE.
A permanent cloud end-point to SmartThings is provided by xooa to enable cloud-to-cloud integration while maintaining peer-to-peer capabilities of blockchain.
Before you begin you may want to fork the SmartThings-xooa repository.
-
Log in or create a xooa account at https://xooa.com/blockchain
-
Click apps, then Deploy New. If this is your first time deploy a chaincode app with xooa, you will need to authorize xooa with your GitHub account.
-
Click Connect to GitHub.
-
Follow the onscreen instructions to complete the authorization process.
-
Enter a name and description for your app, and then click Next.
-
Search for the SmartThings-xooa repo (or your fork). A list of repositories matching the search criteria are shown.
-
Select the repo, and then click Next. The deployment details appear.
-
Select master branch and SmartThings-xooa as the chaincode, and then click Deploy.
-
Relax while Xooa does the blockchain heavy lifting for you. You will be redirected to app dashboard when the deployment completes.
-
Copy the Xooa app ID from the
Basic Information
tab on the Apps dashboard. You will need this ID later to connect the SmartApp. -
From the Apps dashboard, navigate to the Identities tab.
-
For the available identity, click Show API token and copy the token value. You need this token to authorize API requests to the SmartApp.
-
Log in with your Samsung SmartThings account to the SmartThings IDE at https://graph.api.SmartThings.com.
-
Navigate to My SmartApps.
You now need to publish the app. You can do this with or without GitHub integration:
Without GitHub integration:
-
From main menu, select
New SmartApp
. -
Navigate to From code.
-
Locate
blockchain-event-logger.groovy
in the SmartThings-xooa GitHub repo. -
Click Raw.
-
Select all and copy the code.
-
Paste your selection in the From Code section in the SmartThings console, and then click create.
-
Click save.
-
Click Publish -> For me.
With GitHub integration (if you haven't already set up GitHub to work with SmartThings, here is the community FAQ on the subject https://community.SmartThings.com/t/faq-github-integration-how-to-add-and-update-from-repositories/39046)
- Still under SmartApps tab, select Settings.
- Select Add new repository.
- Add the GitHub repo to your IDE with the following parameters:
Owner
: xooaName
: SmartThings-xooaBranch
: master
- Click Save.
- Click Update from Repo.
- Click SmartThings-xooa (master).
- Select blockchain-event-logger.groovy from the New (only in GitHub) column.
- Select Publish.
- Click Execute Update.
There are two apps available for SmartThings in the Google Play store. We recommend the classic app over the new app.
-
Ensure you have the SmartThings app installed on your phone with at least one location and one device defined.
-
Ensure you are using the same login ID you used for your developer account to log in to the app.
-
Open your SmartThings app on your smartphone.
-
Tap automation in the lower bar.
-
Tap the SmartApps tab on top.
-
Tap Add a SmartApp.
-
Scroll to the bottom and then tap My Apps.
-
Identify the
Blockchain Event Logger
app and tap it to proceed. -
Select the devices you want to log in the xooa blockchain.
-
Scroll down and enter the Xooa app ID provided in the xooa dashboard under
Basic Information
. -
Enter the Xooa participant API token provided in xooa dashboard under
Identities
. -
Click Save
-
Tap
automations
in lower bar. -
Tap Add (Android) or + (iOS).
-
If prompted, select the location you want to add the app to.
-
Tap Done (iOS).
-
Find
Blockchain Event Logger
, usually it will appear last and may take a few seconds to appear. -
Tap it to continue setting it up.
-
Select which devices you want to log in the xooa blockchain.
-
Scroll down and enter the Xooa app ID provided in the xooa dashboard under
Basic Information
. -
Enter the Xooa participant API token provided in xooa dashboard under
Identities
.
Follow the same steps as Event Logger SmartApp Setup (SmartThings IDE)
but:
-
Use
blockchain-event-viewer.groovy
instead ofblockchain-event-logger.groovy
from SmartThings-xooa GitHub repo. -
Skip
Event Logger SmartApp Configuration
steps.
-
Tap automation in the lower bar.
-
Tap the SmartApps tab on top.
-
Tap Add a SmartApp.
-
Scroll to the bottom and tap My Apps.
-
Find
Blockchain Event Viewer
and tap it. -
Enter the Xooa app ID provided in the xooa dashboard under
Basic Information
. -
Enter the Xooa participant API token provided in the xooa dashboard under
Identities
. -
Enter the Location Id for which you want to view events. Keep it as it is if you want to view events of your own location.
-
Click Next to proceed to view the devices logging to the blockchain.
-
Click any device to view the past logged events for that device.
-
Input the date for which you want to view the past logged events.(Last logged date is preset)
-
Click Save to store Xooa app ID, API Token and Location Id with SmartApp for future uses.
-
Tap automations in lower bar.
-
Tap Add(in android) or +(in IOS).
-
If prompted, select the location you want to add the app to.
-
Tap Done(in IOS).
-
Find
Blockchain Event Viewer
, usually it appears at the bottom of the page and may take a few seconds to appear. -
Tap the app.
-
Enter the Xooa app ID provided in the xooa dashboard under
Basic Information
. -
Enter the Xooa participant API token provided in xooa dashboard under
Identities
. -
Enter the Location Id for which you want to view events. Keep it as it is if you want to view events of your own location.
-
Click Next to proceed to view devices logging to the blockchain.
-
Click on any device to view the past logged events for that device.
-
Input the date for which you want to view the past logged events.(Latest logged date is preset)
-
Click Save to store the Xooa app ID, API Token and Location Id with SmartApp for future uses.