Blockchainbean
# WARNING: This repository is no longer maintained :warning: This pattern focuses on older technology (e.g. Hyperledger Fabric APIs prior to Fabric 1.4). Therefore, there is no support for this pattern and it will be archived on May 1, 2019. You are welcome to use up to that date, but we recommend that you begin working with the updated release found at https://developer.ibm.com/patterns/coffee-supply-chain-network-hyperledger-fabric-blockchain-2/.
Install / Use
/learn @IBM/BlockchainbeanREADME
WARNING: This repository is no longer maintained :warning:
This pattern focuses on older technology (e.g. Hyperledger Fabric APIs prior to Fabric 1.4). Therefore, there is no support for this pattern and it will be archived on May 1, 2019. You are welcome to use up to that date, but we recommend that you begin working with the updated release found at https://developer.ibm.com/patterns/coffee-supply-chain-network-hyperledger-fabric-blockchain-2/.
SEE updated pattern here: https://github.com/horeaporutiu/blockchainbean2
⚠️⚠️⚠️THE STEPS OUTLINED BELOW WILL NOT WORK. UPDATE IS IN PROGRESS HERE: https://github.com/horeaporutiu/blockchainbean2 - HOREA⚠️⚠️⚠️
This code pattern is based on a recent proof-of-concept developed in collaboration with a coffee roasting company that was nice enough to let us use their supply-chain documents. The link to the application that the code pattern is based off of is here: https://www.ibm.com/thought-leadership/blockchainbean/
All documents that were used in the supply chain are available online, and can be found by clicking the
view the blockchain button at https://www.ibm.com/thought-leadership/blockchainbean/
In this Code Pattern we will create a blockchain app that increases visibility and efficiency in the supply chain of a coffee retailer. The private keys and credentials of the blockchain application will be stored on a Cloudant database. We will use different transactions to show different possible actions for the different participants in the supply chain. This sample application will record all transactions on the IBM Blockchain Starter Plan, and enable a coffee retailer to ensure the customer that their coffee is organic and fair-trade. The Code Pattern can be useful to developers that are looking into learning more about creating applications that mimic a food trust supply chain with Hyperledger Composer.
When the reader has completed this Code Pattern, they will understand how to:
- Interact with IBM Blockchain Starter Plan
- Build a blockchain back-end using Hyperledger Composer
- Create and use Cloudant NoSQL Database
- Deploy a Cloud Foundry application that writes and queries to the ledger

Flow
- User submits transaction proposal using a web-app.
- The web-app talks to a REST API which is running on Cloud Foundry.
- The REST API invokes chaincode on the peers of the blockchain network.
- The peers sign the transaction with their certificates which are held in Cloudant. The ledger is updated on the peers.
Included components
- IBM Blockchain Starter Plan: Use the IBM Blockchain Platform to simplify the developmental, governmental, and operational aspects of creating a blockchain solution.
- Cloudant NoSQL DB: A fully managed data layer designed for modern web and mobile applications that leverages a flexible JSON schema.
Featured technologies
- IBM Blockchain: Blockchain is a shared, immutable ledger for recording the history of transactions.
- Databases: Repository for storing and managing collections of data.
- Cloud: Accessing computer and information technology resources through the Internet.
Watch the Video - Deploy a Hyperledger Composer blockchain network to cloud - Setup (Part 1)
Watch the Video - Deploy a Hyperledger Composer blockchain network to cloud - Setup (Part 2)
Prerequisites
-
If you do not have an IBM Cloud account yet, you will need to create one here.
-
Yeoman, to generate app skeleton.
$ npm install -g generator-hyperledger-composer
$ npm install -g yo
Steps
- Create the toolchain
- Clone the repo
- Use Yeoman to scaffold your project
- Push smart contract code
- Deploy smart contract to IBM Blockchain Starter Plan
- Post transactions and query the Composer REST Server (Swagger UI)
- Launch IBM Blockchain Starter Plan
- Inspect blocks on IBM Blockchain Starter Plan
- Submit fair trade supply data
Step 1. Create the toolchain

Go to https://github.com/sstone1/blockchain-starter-kit. Go to step 2, and click on Set up DevOps toolchain.
Follow steps in the in the README to create your DevOps toolchain, and GitHub repository. At the end of this step you should have a toolchain with a github repo, and a delivery pipeline, as shown in the last part of step 2 of https://github.com/sstone1/blockchain-starter-kit. Just refresh the toolchain page, and you should see your toolchain have 3 parts - think, code, delivery, as shown in the gif below.
Step 2. Clone the repo

Now we need to clone the repo we have just created. Click on the Github button in the middle, which will take you to your new GitHub repo. Now, click on the green clone or download button on the right side of the page. This should give you a URL. Save this, you'll need it in the next step. Now in your terminal, find a place where you would like to start your project. In terminal, execute the following
git clone https://github.com/<yourUsername/projectname>.git
Go into your newly cloned repo. I called my bsk-horea-2.
$ cd bsk-horea-2
Step 3. Use Yeoman to scaffold your project

Now to the fun part, the smart contracts. Let's use Yeoman.
$ npm install -g generator-hyperledger-composer
$ npm install -g yo
$ cd contracts
$ yo
$ -> `Hyperledger Composer`
$ -> `Business Network`
$ Business network name: `coffeetracker4`
$ Description: `demo`
$ Author Name: `Horea`
$ Author Email: `horea@email.com`
$ License: `(Apache-2.0)`
$ Namespace: org.ibm.coffee
$ Do you want to generate an empty template network?: `Yes`
Step 4. Push smart contract code

First, we need to modify some lines from your newly scaffoled application. Let's cut a few lines inside the package.json file. This is found in the
bsk-horea-2/contracts/package.json file.
Let's remove the lines that start with pretest, lint, and test.

Next, let's first clone the blockchain bean directory.
$ git clone https://github.com/IBM/blockchainbean.git
Next, copy and paste the permissions.acl file from
blockchainbean/contracts/coffeeTrackr/permissions.acl
and overwrite your permissions.acl file created from yeoman.

Next, we'll copy the queries.qry file from
blockchainbean/contracts/coffeeTrackr/queries.qry and paste it
in our directory. We shouldn't have a queries.qry yet.
After that, let's rename our bsk-horea-2/contracts/models/org.ibm.coffee.cto file to
bsk-horea-2/contracts/models/model.cto, and copy and paste that same file from the
blockchainbean directory, as we have been doing.
The last file we need is blockchainbean/contracts/coffeeTrackr/lib/logic.js file,
and we can just grab that and paste the contents in bsk-horea-2/contracts/lib/logic.js.

Now, in terminal, let's push our code up to the GitHub repo with the following commands:
$ git add .
$ git commit -m "first commit"
$ git push origin master
Step 5. Deploy smart contract to IBM Blockchain Starter Plan

Now, we need to check our toolchain that we created in Step 2.
Let's go back to our GitHub repo that we just created. Click on the link that says
Created for Toolchain: in the title of the GitHub repo. You will be taken to your IBM Cloud Toolchains page.
Click on the Delivery stage.
The pipeline should be triggered now. If it is not, simply go to it, and press the play button on the Build stage as shown in the gif. Next, wait for the pipeline to start.
If there are errors, you may want to check the logs by pressing the View logs and history option link on the Build stage.
Once the app successfully builds (you can check this with a simple page refresh), the Deploy stage should be triggered. Same as with the Build stage, you may want to check the logs if there are errors.
Let's check the logs of the Deploy stage by clicking the View logs and history button as shown in the gif. We can find the URL of our Cloud Foundry app
by finding the REST_SERVER_URLS line, close to the bottom of the logs as shown in the gif.
Step 6. Post transactions and query the Composer REST Server (Swagger UI)
Once you click on your application URL (this i


