This is a customized version of the code pattern available on IBM developer:
Branch: master
Clone or download
Pull request Compare This branch is 38 commits ahead, 2 commits behind IBM:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Using-Blockchain to-Track-Fitness-Rewards.code-workspace

Using Blockchain to Track Fitness Rewards

Customized by Thomas Suedbroecker

Code Pattern on IBM Developer Fitness Club Rewards points iot and retail integration

If you want to play with blockchain you should just use: playground

Table of content


This is a sample web application that uses a Hyperledger Fabric blockchain to track and trace fitness rewards.

One of the biggest challenges Fitness Clubs face is maintaining members. It is always cheaper to keep a member than attract new members. To retain members, some clubs will offer loyalty programs, but oftentimes, those are ineffective because they may provide future free months or potentially offer a discount to friends and family. Sometimes, the program only rewards members when they refer friends to the club.

In order to make loyalty more effective, there are a few things that will improve the programs:

  1. Rewards for working out incentivizes members to use the facilities
  2. Ability to use their rewards more frequently and for more valuable purchases
  3. Visibility into their rewards lends trust to the program

With Fitcoins, we even add a new feature to loyalty programs, community building. By bringing local merchants into the program, we can facilitate commerce with those merchants that want to be affiliated with the club loyalty program. This provides an easy way for members to transact with the stores using digital currency. The store owners benefit by getting access to customers they may not have had. As the store owners earn Fitcoins through purchases, those Fitcoins could potentially be exchanged for cash from the club or used to maybe purchase advertising at the club. This creates a whole ecosystem around the club and a sense of community.

Functionality of the Fitcoin app

-> BACK to Introduction/UseCase

Fitcoin web app

fit coin webapp

With the Fitcoin app, a Fitness Club can:

  • add new members.

  • For active members you can:

    • simulate those members receiving rewards points
    • redeeming rewards points
    • viewing their rewards points history.
  • Clubs can also deactivate members to simulate members cancelling their memberships, something we hope never happens.

-> BACK to Introduction/UseCase

Hyperledger Composer Model

I using a UML Use Case model to do an approach for a simplified visualization of the cto model file of the fitcoin system.

Here are my used/defined UML sterotypes:

  • transaction is represented as an UML use case
  • participant is represented as an UML actor
  • UML association does represent the dependency inside an transaction to a participant.
  • UML generalization does represent the extend for an participant.

simplified visualization


The *logic for this model is implemented in the ./lib/logic.js


The following image shows the architecture of the Fitcoin system, based on Blockchain.

The components fitcoin webappliction, Hyperledger Composer REST Server and Wolfpack Fitclub Fitcoin Hyperledger Fabric Network.

alt text

1 Flow

-> BACK to Introduction/UseCase

You will install on your local machine and run a sample web application.

  1. Install Hyperledger Fabric and Composer
  2. Build and Deploy the Fitcoin Blockchain Network
  3. Build and run the Fitcoin Angular Web App

2 Technical Pre-requisites to run the sample locally

-> BACK to Introduction/UseCase

  1. At least 4Gb of memory
  2. Operating Systems: Ubuntu Linux 14.04 / 16.04 LTS (both 64-bit), or Mac OS 10.12
  3. Docker Engine: Version 17.03 or higher
  4. Docker-Compose: Version 1.8 or higher**
  5. Node: 8.9 or higher (note version 9 is not supported)
  6. npm: v5.x
  7. git: 2.9.x or higher
  8. Python: 2.7.x
  9. Axios:
  10. Type Script: for the WebApplication

2.1 Installing/setup pre-requisites

-> BACK to Introduction/UseCase

The following steps do contain the steps to install the given technical pre-requisites to run the sample locally on your PC.

2.1.1 Ubuntu

-> BACK to Introduction/UseCase

  1. Login as a normal user, rather than root.
  2. Do not su to root.
  3. When installing prerequisites, use curl, then unzip using sudo.
  4. Run as a normal user. It may prompt for root password as some of it's actions are required to be run as root.
  5. Do not use npm with sudo or su to root to use it.
  6. Avoid installing node globally as root.

If you're running on Ubuntu, you can download the prerequisites using the following commands:

curl -O

chmod u+x

Next run the script - as this briefly uses sudo during its execution, you will be prompted for your password.


2.1.2 MacOS

-> BACK to Introduction/UseCase

Note: Mac OS X version 10.12.6 was used for these instructions. Install nvm and Apple Xcode

-> BACK to Introduction/UseCase

First install nvm (the Node version manager). nvm is a tool that allows you to easily install, update and switch between versions of Node.js.

Open the terminal (command line) by clicking on the magnifier in the menu bar at the top right of your screen. Type terminal and press enter.

In the terminal window paste the text below and press enter:

curl -o- | bash

More information on this script and the Node install process is available here.

When you hit enter you should see the pop-up below, prompting you to install git. Press the Get Xcode button to install the full Apple Xcode IDE, including a C++ compiler, used to install native Node.js modules.

The download and install process for Xcode may take 20 minutes or more. Be patient!

After the installation of Xcode has completed launch Xcode. Accept the license agreement. It will prompt you for your username and password and will install additional components.

After Xcode finishes installing additional components and launches, simply quit Xcode.

Switch back to the terminal and create your bash profile (stores user preferences for bash):

touch .bash_profile

Then retrun the original curl command:

curl -o- | bash

Close the terminal and reopen it.

Check that nvm is installed and is accessible:

nvm —-version

2.1.3 Install Node (Ubuntu and Mac)

-> BACK to Introduction/UseCase

Install the latest (long term support) version of Node:

nvm install --lts

Switch to the LTS version of Node:

nvm use --lts

Check that Node is installed:

node --version

2.1.4 Install Docker (Ubuntu and Mac)

-> BACK to Introduction/UseCase

Follow the instructions here to install Docker for Mac (stable):

After running the installed Docker application you should have the whale icon in your menu bar, with a green “Docker is running” status.

3 The Blockchain sample is based on three major components

-> BACK to Introduction/UseCase

You have to follow later the different readmes in this github project.

  1. Hyperledger Fabric and Hyperledger Composer

This sub-project obtains the Hyperledger Composer development tools (primarily used to create Business Networks) and stand up a Hyperledger Fabric (primarily used to run/deploy your Business Networks locally).

Note: The Business Networks you create can also be deployed to Hyperledger Fabric runtimes in other environments e.g. on a cloud platform.

  1. Fitcoin Blockchain Network Archive

This sub-project includes the definition of the Hyperledger Fabric and Composer blockchain network. Hyperledger models consist of a few components.

  1. Fitcoin Angular Web App

In that sub-project you can find the sample webapplication.

The users will interact with the blockchain through a web UI written using Node.js and Angular 2 (6.x) framework.

3.1 Featured Technologies in the Blockchain project

-> BACK to Introduction/UseCase

The following technologies are used to implement the sample application.

  1. Angular
  2. Node.js
  3. Docker
  4. NVM
  5. Apple Xcode

4 Steps

-> BACK to Introduction/UseCase

These are the steps to setup the Blockchain sample. You have to follow the readme to each step.

fitcoin steps

  1. Install Hyperledger Fabric and Composer
  2. Build and deploy the Fitcoin Blockchain Network
  3. Build and run the Fitcoin Angular Web App

5 Links

-> BACK to Introduction/UseCase

6 Learn more

-> BACK to Introduction/UseCase

  • Blockchain 101: Learn why IBM believes that blockchain can transform businesses, industries – and even the world. Blockchain 101

7 License

-> BACK to Introduction/UseCase

Apache 2.0