Friday, June 15, 2018

Developer tutorial for creating a IBM Blockchain Platform: Develop solution



This tutorial will walk you through building a IBM Blockchain Platform: Develop blockchain solution from scratch. In the space of a few hours you will be able to go from an idea for a disruptive blockchain innovation, to executing transactions against a real Hyperledger Fabric blockchain network and generating/running a sample Angular 4 application that interacts with a blockchain network.

This tutorial gives an overview of the techniques and resources available to apply to your own use case.

Note: This tutorial was written against the latest IBM Blockchain Platform: Develop build on Ubuntu Linux running with Hyperledger Fabric where referenced below and also tested for a Mac environment.

Prerequisites
Before beginning this tutorial:

Step One: Creating a business network structure

The key concept for IBM Blockchain Platform: Develop is the business network definition (BND). It defines the data model, transaction logic and access control rules for your blockchain solution. To create a BND, we need to create a suitable project structure on disk.

The easiest way to get started is to use the Yeoman generator to create a skeleton business network. This will create a directory containing all of the components of a business network.

1. Create a skeleton business network using Yeoman. This command will require a business network name, description, author name, author email address, license selection and namespace.
yo hyperledger-composer:businessnetwork
2. Enter tutorial-network for the network name, and desired information for description, author name, and author email.
3. Select Apache-2.0 as the license.
4. Select org.example.mynetwork as the namespace.
5. Select No when asked whether to generate an empty network or not.

This will create a folder named tutorial-network in the current directory and you will see the folders and files that created as shown in the above screen shot.

Step Two: Defining a business network

A business network is made up of assets, participants, transactions, access control rules, and optionally events and queries. In the skeleton business network created in the previous steps, there is a model (.cto) file which will contain the class definitions for all assets, participants, and transactions in the business network. The skeleton business network also contains an access control (permissions.acl) document with basic access control rules, a script (logic.js) file containing transaction processor functions, and a package.json file containing business network metadata.

Modelling assets, participants, and transactions
The first document to update is the model (.cto) file. This file is written using the IBM Blockchain Platform: Develop Modelling Language. The model file contains the definitions of each class of asset, transaction, participant, and event. It implicitly extends the IBM Blockchain Platform: Develop System Model described in the modelling language documentation.

1. Go to the folder tutorial-network/model
2. Open the org.example.mynetwork.cto model file.
3. Replace the contents with the following:
/**
 * My commodity trading network
 */
namespace org.example.mynetwork
asset Commodity identified by tradingSymbol {
    o String tradingSymbol
    o String description
    o String mainExchange
    o Double quantity
    --> Trader owner
}
participant Trader identified by tradeId {
    o String tradeId
    o String firstName
    o String lastName
}
transaction Trade {
    --> Commodity commodity
    --> Trader newOwner
}
4. Save your changes to org.example.mynetwork.cto.

Adding JavaScript transaction logic
In the model file, a Trade transaction was defined, specifying a relationship to an asset, and a participant. The transaction processor function file contains the JavaScript logic to execute the transactions defined in the model file.

The Trade transaction is intended to simply accept the identifier of the Commodity asset which is being traded, and the identifier of the Trader participant to set as the new owner.

1. Go to the folder tutorial-network/lib/
2. Open the logic.js script file.
3. Replace the contents with the following:
/**
 * Track the trade of a commodity from one trader to another
 * @param {org.example.mynetwork.Trade} trade - the trade to be processed
 * @transaction
 */
async function tradeCommodity(trade) {
    trade.commodity.owner = trade.newOwner;
    let assetRegistry = await getAssetRegistry('org.example.mynetwork.Commodity');
    await assetRegistry.update(trade.commodity);
}
4. Save your changes to logic.js.

Adding access control
1. Replace the following access control rules in the file permissions.acl :
/**
 * Access control rules for tutorial-network
 */
rule Default {
    description: "Allow all participants access to all resources"
    participant: "ANY"
    operation: ALL
    resource: "org.example.mynetwork.*"
    action: ALLOW
}

rule SystemACL {
  description:  "System ACL to permit all access"
  participant: "ANY"
  operation: ALL
  resource: "org.hyperledger.composer.system.**"
  action: ALLOW
}
2. Save your changes to permissions.acl.

Step Three: Generate a business network archive
Now that the business network has been defined, it must be packaged into a deployable business network archive (.bna) file.

1. Using the command line, navigate to the tutorial-network directory.
2. From the tutorial-network directory, run the following command:
composer archive create -t dir -n .

After the command has run, a business network archive file called tutorial-network@0.0.1.bna has been created in the tutorial-network directory.

Step Four: Deploying the business network
After creating the .bna file, the business network can be deployed to the instance of Hyperledger Fabric. Normally, information from the Fabric administrator is required to create a PeerAdmin identity, with privileges to install chaincode to the peer as well as start chaincode on the composerchannel channel. However, as part of the development environment installation, a PeerAdmin identity has been created already.

After the business network has been installed, the network can be started. For best practice, a new identity should be created to administer the business network after deployment. This identity is referred to as a network admin.

Retrieving the correct credentials
A PeerAdmin business network card with the correct credentials is already created as part of development environment installation.

Deploying the business network
Deploying a business network to the Hyperledger Fabric requires the IBM Blockchain Platform: Develop business network to be installed on the peer, then the business network can be started, and a new participant, identity, and associated card must be created to be the network administrator. Finally, the network administrator business network card must be imported for use, and the network can then be pinged to check it is responding.

1. To install the business network, from the tutorial-network directory, run the following command:

composer network install --card PeerAdmin@hlfv1 --archiveFile tutorial-network@0.0.1.bna

The composer network install command requires a PeerAdmin business network card (in this case one has been created and imported in advance), and the the file path of the .bna which defines the business network.

2. To start the business network, run the following command:

composer network start --networkName tutorial-network --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card

The composer network start command requires a business network card, as well as the name of the admin identity for the business network, the name and version of the business network and the name of the file to be created ready to import as a business network card.

3. To import the network administrator identity as a usable business network card, run the following command:

composer card import --file networkadmin.card

The composer card import command requires the filename specified in composer network start to create a card.

4. To check that the business network has been deployed successfully, run the following command to ping the network:

composer network ping --card admin@tutorial-network

The composer network ping command requires a business network card to identify the network to ping.

Step Five: Generating a REST server
IBM Blockchain Platform: Develop can generate a bespoke REST API based on a business network. For developing a web application, the REST API provides a useful layer of language-neutral abstraction.

1. To create the REST API, navigate to the tutorial-network directory and run the following command:
composer-rest-server
2. Enter admin@tutorial-network as the card name.
3. Select never use namespaces when asked whether to use namespaces in the generated API.
4. Select No when asked whether to secure the generated API.
5. Select Yes when asked whether to enable event publication.
6. Select No when asked whether to enable TLS security.

The generated API is connected to the deployed blockchain and business network.
Note: The REST Server will try to start on Port 3000. In my case, the port 3000 is already in use, so I have to use the following command:

composer-rest-server -c admin@tutorial-network -p 3010

This will default the rest of the parameters.

Step Six: Generating an application
IBM Blockchain Platform: Develop can also generate an Angular 4 application running against the REST API.
1. To create your Angular 4 application, navigate to tutorial-network directory and run the following command:
yo hyperledger-composer:angular
2. Select Yes when asked to connect to running business network.
3. Enter standard package.json questions (project name, description, author name, author email, license)
4. Enter admin@tutorial-network for the business network card.
5. Select Connect to an existing REST API
6. Enter http://localhost for the REST server address.
7. Enter 3000 for server port.
8. Select Namespaces are not used

The Angular generator will then create the scaffolding for the project and install all dependencies. To run the application, navigate to your angular project directory and run npm start . This will fire up an Angular 4 application running against your REST API at http://localhost:4200

IBM Blockchain Platform: Installing the development environment


Follow these instructions to obtain the IBM Blockchain Platform: Develop development tools (primarily used to create Business Networks) and stand up a Hyperledger Fabric (primarily used to run/deploy your Business Networks locally). Note that the Business Networks you create can also be deployed to Hyperledger Fabric runtimes in other environments e.g. on a cloud platform.

To provide flexibility and enable the maximum number of dev, test and deployment scenarios, Blockchain Platform is delivered as a set of components you can install with npm and control from the CLI. These instructions will tell you how to install everything first, then how to control your development environment.

Installing components

Step 1: Install the CLI tools
There are a few useful CLI tools for Blockchain Platform developers. The most important one is composer-cli, which contains all the essential operations, so we'll install that first. Next, we'll also pick up generator-hyperledger-composer, composer-rest-server and Yeoman plus the generator-hyperledger-composer. Those last 3 are not core parts of the development environment, but they'll be useful if you're following the tutorials or developing applications that interact with your Business Network, so we'll get them installed now.

1. Essential CLI tools:

npm install -g composer-cli

2. Utility for running a REST Server on your machine to expose your business networks as RESTful APIs:

npm install -g composer-rest-server

3. Useful utility for generating application assets:

npm install -g generator-hyperledger-composer

4. Yeoman is a tool for generating applications, which utilises generator-hyperledger-composer:

npm install -g yo

Step 2: Install Playground

If you've already tried Blockchain Platform online, you'll have seen the browser app "Playground". You can run this locally on your development machine too, giving you a UI for viewing and demonstrating your business networks.

1. Browser app for simple editing and testing Business Networks:

npm install -g composer-playground

Step 3: Set up your IDE
Whilst the browser app can be used to work on your Business Network code, most users will prefer to work in an IDE. Our favourite is VSCode, because a Blockchain Platform extension is available.

1. Install VSCode from this URL: https://code.visualstudio.com/download

2. Open VSCode, go to Extensions, then search for and install the Hyperledger Composer extension from the Marketplace.

Step 4: Install Hyperledger Fabric
This step gives you a local Hyperledger Fabric runtime to deploy your business networks to.

1. In a directory of your choice (we will assume ~/fabric-dev-servers), get the .tar.gz file that contains the tools to install Hyperledger Fabric:

mkdir ~/fabric-dev-servers && cd ~/fabric-dev-servers

curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.tar.gz
tar -xvf fabric-dev-servers.tar.gz

A zip is also available if you prefer: just replace the .tar.gz file with fabric-dev-servers.zip and the tar -xvf command with a unzip command in the preceding snippet.

2. Use the scripts you just downloaded and extracted to download a local Hyperledger Fabric runtime:

cd ~/fabric-dev-servers
./downloadFabric.sh

Congratulations, you've now installed everything required for the typical Developer Environment. Read on to learn some of the most common things you'll do with this environment to develop and test your Blockchain Business Networks.

Controlling your dev environment
Starting and stopping Hyperledger Fabric
You control your runtime using a set of scripts which you'll find in ~/fabric-dev-servers if you followed the suggested defaults.

The first time you start up a new runtime, you'll need to run the start script, then generate a PeerAdmin card:

    cd ~/fabric-dev-servers
    ./startFabric.sh
    ./createPeerAdminCard.sh

Note: While running the above createPeerAdminCard.sh, if you encounter the below error, please follow the solution mentioned below:
===============
Error details:
$ sudo ./createPeerAdminCard.sh   Development only script for Hyperledger Fabric control
Running 'createPeerAdminCard.sh'
FABRIC_VERSION is unset, assuming hlfv11
FABRIC_START_TIMEOUT is unset, assuming 15 (seconds)

No version of composer-cli has been detected, you need to install composer-cli at v0.19 or higher

Solution:
1. Know the path where composer is installed by running the command 
where composer
It will mention the path where composer-cli is installed. Let's say the output is ~/.nvm/versions/node/v8.11.2/bin/composer
2. Now you need to add the alias into .bash_aliases file to make it work whenever you open the terminal.
a) First navigate to your user path using the bellow command.
cd ~
b) Then create or open a file named .bash_aliases in the home user path using the following command.
nano .bash_aliases
c) Then add the alias composer='~/.nvm/versions/node/v8.11.2/bin/composer' to that file and save it. So it will be work even after you restarting the system.
d) Now you can execute the createPeerAdminCard.sh and you will not encounter the error.
===============


You can start and stop your runtime using ~/fabric-dev-servers/stopFabric.sh, and start it again with ~/fabric-dev-servers/startFabric.sh.

At the end of your development session, you run ~/fabric-dev-servers/stopFabric.sh and then ~/fabric-dev-servers/teardownFabric.sh. Note that if you've run the teardown script, the next time you start the runtime, you'll need to create a new PeerAdmin card just like you did on first time startup.

The local runtime is intended to be frequently started, stopped and torn down, for development use. If you're looking for a runtime with more persistent state, you'll want to run one outside of the dev environment, and deploy Business Networks to it. Examples of this include running it via Kubernetes, or on a managed platform such as IBM Cloud.

Start the web app ("Playground")
To start the web app, run:
composer-playground
It will typically open your browser automatically, at the following address: http://localhost:8080/login

You should see the PeerAdmin@hlfv1 Card you created with the createPeerAdminCard script on your "My Business Networks" screen in the web app: if you don't see this, you may not have correctly started up your runtime!

Congratulations, you've got all the components running, and you also know how to stop and tear them down when you're done with your dev session.

IBM Blockchain Platform: Develop concepts using the online playground environment

Playground Tutorial

In this step by step tutorial we'll walk through setting up a business network, defining our assets, participants and transactions, and testing our network by creating some participants and an asset, and submitting transactions to change the ownership of the asset from one to another. This tutorial is intended to act as an introduction to IBM Blockchain Platform: Develop concepts using the online playground environment.

Step One: Open the IBM Blockchain Platform: Develop Playground

Open Blockchain Platform Playground (note, this link will take you to the web Blockchain Platform Playground - you can also follow along in a local version if you've already installed the development environment).

You should see the My Business Networks screen. The My Business Networks page shows you a summary of the business networks you can connect to, and the identities you can use to connect to them. Don't worry about this too much for the time being, as we're going to create our own network.

Step Two: Creating a new business network

Next, we want to create a new business network from scratch. A business network has a couple of defining properties; a name, and an optional description. You can also choose to base a new business network on an existing template, or import your own template.

Next, we want to create a new business network from scratch. A business network has a couple of defining properties; a name, and an optional description. You can also choose to base a new business network on an existing template, or import your own template.
  • Click Deploy a new business network under the Web Browser heading to get started.
  • The new business network needs a name, let's call it tutorial-network.
  • Optionally, you can enter a description for your business network.
  • Next we must select a business network to base ours on, because we want to build the network from scratch, click empty-business-network.
  • Now that our network is defined, click Deploy.

NOTE: If you are using playground locally and connecting to a real Fabric please refer to the additional notes at the bottom of the tutorial.




Step Three: Connecting to the business network

Now that we've created and deployed the business network, you should see a new business network card called admin for our business network tutorial-network in your wallet. The wallet can contain business network cards to connect to multiple deployed business networks.

When connecting to an external blockchain, business network cards represent everything necessary to connect to a business network. They include connection details, authentication material, and metadata.

To connect to our business network click Connect now under our business network card


Step Four: Adding a model file

As you can see, we're in the Define tab right now, this tab is where you create and edit the files that make up a business network definition, before deploying them and testing them using the Test tab.

As we selected an empty business network template, we need to modify the template files provided. The first step is to update the model file. Model files define the assets, participants, transactions, and events in our business network.

For more information on our modeling language, check our documentation.
  1. Click the Model file to view it.
  2. Delete the lines of code in the model file and replace it with this:
/**
 * My commodity trading network
 */
namespace org.example.mynetwork
asset Commodity identified by tradingSymbol {
    o String tradingSymbol
    o String description
    o String mainExchange
    o Double quantity
    --> Trader owner
}
participant Trader identified by tradeId {
    o String tradeId
    o String firstName
    o String lastName
}
transaction Trade {
    --> Commodity commodity
    --> Trader newOwner
}
This domain model defines a single asset type Commodity and single participant type Trader and a single transaction type Trade that is used to modify the owner of a commodity.

Step Five: Adding a transaction processor script file

Now that the domain model has been defined, we can define the transaction logic for the business network. Composer expresses the logic for a business network using JavaScript functions. These functions are automatically executed when a transaction is submitted for processing.

For more information on writing transaction processor functions, check our documentation.

  1. Click the Add a file button.
  2. Click the Script file and click Add.
  3. Delete the lines of code in the script file and replace it with the following code:
/**
 * Track the trade of a commodity from one trader to another
 * @param {org.example.mynetwork.Trade} trade - the trade to be processed
 * @transaction
 */
async function tradeCommodity(trade) {
    trade.commodity.owner = trade.newOwner;
    let assetRegistry = await getAssetRegistry('org.example.mynetwork.Commodity');
    await assetRegistry.update(trade.commodity);
}

This function simply changes the owner property on a commodity based on the newOwner property on an incoming Trade transaction. It then persists the modified Commodity back into the asset registry, used to store Commodity instances.

Step Six: Access control:
Access control files define the access control rules for business networks. Our network is simple, so the default access control file doesn't need editing. The basic file gives the current participant networkAdmin full access to business network and system-level operations.

While you can have multiple model or script files, you can only have one access control file in any business network.

Step Seven: Deploying the updated business network
Now that we have model, script, and access control files, we need to deploy and test our business network.

Click Deploy changes to upgrade the business network.

NOTE: If you are using playground locally and connecting to a real Fabric please refer to the additional notes at the bottom of the tutorial.


Step Eight: Testing the business network definition

Next, we need to test our business network by creating some participants (in this case Traders), creating an asset (a Commodity), and then using our Trade transaction to change the ownership of the Commodity.

Click the Test tab to get started.

Step Nine: Creating participants
The first thing we should add to our business network is two participants.

  1. Ensure that you have the Trader tab selected on the left, and click Create New Participant in the upper right
  2. What you can see is the data structure of a Trader participant. We want some easily recognizable data, so delete the code that's there and paste the following:
{
  "$class": "org.example.mynetwork.Trader",
  "tradeId": "TRADER1",
  "firstName": "Jenny",
  "lastName": "Jones"
}
      3. Click Create New to create the participant.
      4. You should be able to see the new Trader participant you've created. We need another Trader to test our Trade transaction though, so create another Trader, but this time, use the following data
{
  "$class": "org.example.mynetwork.Trader",
  "tradeId": "TRADER2",
  "firstName": "Amy",
  "lastName": "Williams"
}

Make sure that both participants exist in the Trader view before moving on!

Step Ten: Creating an asset
Now that we have two Trader participants, we need something for them to trade. Creating an asset is very similar to creating a participant. The Commodity we're creating will have an owner property indicating that it belongs to the Trader with the tradeId of TRADER1.

  1. Click the Commodity tab under Assets and click Create New Asset.
  2. Delete the asset data and replace it with the following:
  3. {
      "$class": "org.example.mynetwork.Commodity",
      "tradingSymbol": "ABC",
      "description": "Test commodity",
      "mainExchange": "Euronext",
      "quantity": 72.297,
      "owner": "resource:org.example.mynetwork.Trader#TRADER1"
    }
  4. After creating this asset, you should be able to see it in the Commodity tab.

Step Eleven: Transferring the commodity between the participants
Now that we have two Traders and a Commodity to trade between them, we can test our Trade transaction.

Transactions are the basis of all change in a IBM Blockchain Platform: Develop business network, if you want to experiment with your own after this tutorial, try creating another business network from the My Business Network screen and using a more advanced business network template.

To test the Trade transaction:
  1. Click the Submit Transaction button on the left.
  2. Ensure that the transaction type is Trade.
  3. Replace the transaction data with the following, or just change the details:
  4. {
      "$class": "org.example.mynetwork.Trade",
      "commodity": "resource:org.example.mynetwork.Commodity#ABC",
      "newOwner": "resource:org.example.mynetwork.Trader#TRADER2"
    }
  5. Click Submit.
  6. Check that our asset has changed ownership from TRADER1 to TRADER2, by expanding the data section for the asset. You should see that the owner is listed as resource:org.example.mynetwork.Trader#TRADER2.
  7. To view the full transaction history of our business network, click All Transactions on the left. Here is a list of each transaction as they were submitted. You can see that certain actions we performed using the UI, like creating the Trader participants and the Commodity asset, are recorded as transactions, even though they're not defined as transactions in our business network model. These transactions are known as 'System Transactions' and are common to all business networks, and defined in the IBM Blockchain Platform: Develop Runtime.
Logging out of the business network:

Now that transactions have successfully run, we should log out of the business network, ending up at the My Business Network screen where we started.

In the upper-right of the screen is a button labelled admin. This lists your current identity, to log out, click admin to open the dropdown menu, and click My Business Networks.

Deploying a Business Network to a real Fabric.

Using Playground locally, you can use connections to "Web Browser" which works in the browser local storage, or you can use Connections to a real Fabric usually in a group called "hlfv1"

If you are connecting to a real Fabric, then you will likely have already created a Card for an identity with PeerAdmin and ChannelAdmin roles - this is often called PeerAdmin. This is the card that you use to Deploy and Update your network with Composer.

When you are deploying your network to a real Fabric there are additional fields to complete before you can click the Deploy button - you need to supply the details of the Network Administrator.

Scroll to the bottom of the Deploy Screen to find CREDENTIALS FOR NETWORK ADMINISTRATOR. For a simple Development Fabric and many Test networks you can supply an ID and Secret. Enrollment ID - admin Enrollment Secret - adminpw

When the ID and Secret are specified, you can click the Deploy button and resume the tutorial at Step Three.

If you are working with a Custom or Production Fabric - contact your Fabric Administrator for details of the Network Administrator.

Updating a Business Network when connected to a real Fabric

When you are using a real Fabric and click Deploy Changes you will see an addition popup dialog asking you to specify an Installation Card and an Upgrade card from dropdown lists. Typically you specify the same PeerAdmin card as used to deploy the initial network. If you are uncertain, contact your Fabric Administrator.

Select the cards, and click the Upgrade button. Note that on a real Fabric this can take a few minutes to complete.

Resume the Tutorial at Step Eight.

Thursday, June 14, 2018

5 ways blockchain is transforming Financial Services



The Financial Services industry is fundamentally about facilitating the trusted exchange of value between multiple, untrusting parties. Brokering that trust is an enormous responsibility and carries significant risk, which is why the industry has become increasingly reliant on costly intermediaries, manual processes, and error-prone reconciliations. Today, more and more Financial Services institutions are looking to blockchain to enable more efficient cross-organizational collaboration, eliminate intermediaries, and create disruptive business models.
Blockchain appeared in 2008 as the basis of the Bitcoin protocol. Bitcoin’s combination of cryptography and distributed systems enables value to be transferred as quickly as the internet transfers data. While this was initially limited to facilitating immediate "spot" transactions, new protocols such as Corda and Ethereum eventually enabled users to set terms under which they would transfer value at a future point in time. It was then that enterprises – particularly in the financial services industry – began to take notice.

Over the past 2-3 years, blockchain has emerged as a viable technology for addressing multi-party business processes and value exchange without complex shared data schemes and third-party intermediaries. At its core, a blockchain is a secure, shared, distributed ledger – a new shared data structure where banks can record transactions and work together to validate updates. Smart contracts act as a shared tool to govern changes to the underlying ledger in accordance to pre-agreed rules or terms.

This shared record enables organizations to collaborate more efficiently – and because every member of the network holds a record of every transaction, it is nearly impossible to manipulate data undetected. While cryptocurrencies like Bitcoin were responsible for popularizing blockchain technology, blockchain protocols with business-oriented uses are now proliferating, revealing the value of this innovative technology to disrupt business models and transform operations. This offers three key benefits:

1) Risk Mitigation
2) Cost Reduction
3) Improved Customer Outcomes

Let’s take a look at five functions of Financial Services that are already being transformed by blockchain technology.

1. Trade Finance - Risk Mitigation & Cost Reduction

Helping to mange the financial risk of international trade for importing and exporting parties

Current state
Today’s solutions for managing trade finance are built on antiquated technology and processes that exist in silos. This adds significant risks, complexity, and time into trade processes, as all parties have to manually verify data. Pain points include:
  • Error-prone, manual processes for creating, validating, and auditing trade data and documentation
  • Siloed data that is difficult to verify, leading to multiple versions of the truth and major fraud, compliance, and audit risks
  • Disconnected legacy systems that limit new business opportunities and make it difficult for small and medium businesses to gain access to financing alternatives


Future state
Blockchain opens the door for streamlined trade finance, enabling participants to exchange data easily and track assets in real-time. Corda can be leveraged, where it is an enterprise-grade ledger that enables banks to limit who sees what information and selectively share data with only relevant parties. The solution involves blockchain technology paired with any cloud services and APIs, and could be used in the future to involve technologies like AI, machine learning, IoT, and more. Benefits include:
  • Simplified integration between banks, corporations, and the ecosystem of trade service providers of KYC and credit data
  • Reduced risk of fraud and lower compliance costs
  • New business opportunities enabled by ease of connections to new origination sources and the ability to build secure data pipelines to pools of financeable assets


2. Commercial Insurance: Risk Mitigation & Cost Reduction

High-value insurance scenarios, such as reinsurance, or maritime and aviation insurance

Current state
Specialty insurance deals with high-value assets and typically requires collaboration between many parties: insurers, consumers, brokers, aggregators, platforms, reinsurers, banks, and more. This means that guaranteeing visibility and efficiency between each party is critical. Pain points include:
  • Siloed information and lack of standardization of documents and policies results in time and money wasted on manually resolving different data sets
  • Lack of real-time visibility into asset location and condition
  • Difficulty of accurate underwriting and pricing, due to lack of clarify
  • Inefficient, paper-based tracking mechanisms, resulting in time-intensive audits
  • High incidence of fraud and financial crime


Future state
Blockchain’s ability to provide a single source of truth provides massive operational simplification and data transparency between many parties. Furthermore, blockchain can facilitate the creation of trade consortiums that many organizations can easily join, such as the platform created by EY, Microsoft, and Guardtime. Benefits include:
  • Reduced frictional costs and administrative burden, faster payment reconciliation, indisputable audit trails, and lower risk of fraud
  • Improved data quality through real-time visibility into the location, condition, and safety of high-value assets moving around the world
  • Accurate, dynamic, and fair underwriting and pricing based on better risk assessments
  • Better customer service by improving timeliness of claims’ processing and payments


3. Regulatory Compliance: Risk Mitigation, Cost Reduction

Maintaining and documenting compliance with government regulations – such as DoddFrank, Basel III, and KYC/AML – meant to ensure stability and resiliency of markets, protect consumers, and prevent money laundering

Current state
Regulatory requirements are critical to ensuring stability and resiliency of markets, protecting consumers, and reducing the risk of criminal behavior – but maintaining compliance is a hurdle for banks. Failure to prove compliance may result in massive fines.
Pain points include:
  • Duplicative and siloed data sources
  • Time-consuming, manual review, reconciliation, and auditing processes
  • Difficulty maintaining data lineage across multiple systems
  • Risk of data breach at multiple steps in the process


Future state
Blockchain can enable faster, more accurate, more secure reporting by automating compliance processes that draw on undisputable data sources.
  • Private blockchains like Corda, Hyperledger enable regulator nodes to “pull” more trade data in a consistent format, requiring less active resourcing from banks
  • Secure recording, storage, and review of customer and transaction data throughout the lifecycle, resulting in a significant reduction in back office regulatory reporting costs
  • Aggregation of traditionally siloed data sources
  • Regulators can use blockchain to check for compliance in real time, reducing the need for costly inperson audits


4. Claims Processing: Risk Mitigation, Cost Reduction, Improved Customer Outcomes

Processing insurance disbursements to beneficiaries while protecting against fraud

Current state
The insurance industry is particularly vulnerable to having multiple disparate copies of the same data – and the process of mediating between different versions of the truth is time-consuming and expensive. Pain points include:
  • Time-consuming and expensive process of gathering information for assessments
  • Differing opinions about the correct value of a claim between a claimant, insurer, broker, adjuster, and more
  • Customer frustration due to opaque processes and delays in claims processing
  • Threat of insurance fraud


Future state
Automatic claims built on blockchain smart contracts enable a single version of the truth for claim data, increase trust between parties, and create a more efficient claims process.
Benefits include:
  • More accurate assessments through historical claims data
  • Integrated data source for all parties, reducing conflicts about claim value
  • Automatic disbursement when criteria are met, reducing hassle for beneficiary
  • Reduced risk of fraudulent claims


5. B2B Contract Processing: Cost Reduction, Improved Customer Outcomes

Services offered by a bank to act as an intermediary between two contracting parties, securely store contract documentation, hold money in escrow, or guarantee a loan

Current state
The current process of contract processing, such as setting up a bank guarantee, often requires multiple in-person meetings between multiple parties and the bank – and this can be a frustrating process. Pain points include:
  • Time-consuming creation process for all parties, often requiring multiple in-person visits to the bank to go over paperwork
  • Repetitive verification process for any changes to the agreement
  • Heavy dependence on physical documents, which run the risk of getting lost


Future state
Banks can use blockchain technology to build secure Digital Lockers that store sensitive documents. By creating and maintaining contracts in a Digital Locker, banks can enable all parties to easily and securely collaborate on documents. Benefits include:
  • Superior customer experience, as customers no longer have to make multiple bank visits
  • Faster and easier document verification and approval
  • Increased security and ease of access for documents
  • Instead of meeting in-person to create and update bank guarantees, the borrower, lender, and bank can all collaborate in real-time on documents stored in a secure digital locker


Conclusion:

We’ve seen five areas of the Financial Services industry where blockchain is already showing promise by enabling dramatically reduced risks, lowered costs, and improved customer experience. As blockchain technology grows and matures, it will create dramatic shifts in the industry that will go beyond improving existing processes.
Across the entire life of an asset, blockchain can provide total visibility of movement between banks and customers. This represents a total shift in the longstanding “financial supply chain” from opaque and siloed to transparent and indisputable. With a new era of radical transparency and efficiency improvements, intermediaries can be replaced with direct, trusting relationships between financial institutions and their customers. 

Blockchain's importance is so well realized that there are many strartup and enterprises who are investing in Blockchain. Below is the global landscape of Blockchain companies in Financial services, a report prepared by William Mougayar from http://startupmanagement.org

Here is where you can find the PDF Version of this copy and here is the Googlesheet version.




Tuesday, June 5, 2018

Hyperledger Composer - Installation


Installing pre-requisites

The Hyperledger Composer pre-requisites can be installed on Ubuntu or MacOS. Choose your operating system to jump to the appropriate section, or scroll down to find the instructions:

Ubuntu
To run Hyperledger Composer and Hyperledger Fabric, we recommend you have at least 4Gb of memory.

The following are prerequisites for installing the required development tools:

  • Operating Systems: Ubuntu Linux 14.04 / 16.04 LTS (both 64-bit), or Mac OS 10.12
  • Docker Engine: Version 17.03 or higher
  • Docker-Compose: Version 1.8 or higher
  • Node: 8.9 or higher (note version 9 is not supported)
  • npm: v5.x
  • git: 2.9.x or higher
  • Python: 2.7.x
  • A code editor of your choice, we recommend VSCode.

**If installing Hyperledger Composer using Linux, be aware of the following advice:

  • Login as a normal user, rather than root.
  • Do not su to root.
  • When installing prerequisites, use curl, then unzip using sudo.
  • Run prereqs-ubuntu.sh as a normal user. It may prompt for root password as some of it's actions are required to be run as root.
  • Do not use npm with sudo or su to root to use it.
  • Avoid installing node globally as root.**

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

curl -O https://hyperledger.github.io/composer/prereqs-ubuntu.sh
chmod u+x prereqs-ubuntu.sh

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

./prereqs-ubuntu.sh

Installing the development environment

Follow these instructions to obtain 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 that the Business Networks you create can also be deployed to Hyperledger Fabric runtimes in other environments e.g. on a cloud platform.

Before you begin
Make sure you have installed the required pre-requisites, following the instructions in Installing pre-requisites.

These instructions assume that you've not installed the tools and used them before. If this is not the case, you might want to check that your previous setup is completely destroyed before you start following this guide. To learn how to do this, skip to the Appendix.


To provide flexibility and enable the maximum number of dev, test and deployment scenarios, Composer is delivered as a set of components you can install with npm and control from the CLI. These instructions will tell you how to install everything first, then how to control your development environment.

Installing components
Step 1: Install the CLI tools
There are a few useful CLI tools for Composer developers. The most important one is composer-cli, which contains all the essential operations, so we'll install that first. Next, we'll also pick up generator-hyperledger-composer, composer-rest-server and Yeoman plus the generator-hyperledger-composer. Those last 3 are not core parts of the development environment, but they'll be useful if you're following the tutorials or developing applications that interact with your Business Network, so we'll get them installed now.

1. Essential CLI tools:
npm install -g composer-cli

2. Utility for running a REST Server on your machine to expose your business networks as RESTful APIs:
npm install -g composer-rest-server

3. Useful utility for generating application assets:
npm install -g generator-hyperledger-composer

4. Yeoman is a tool for generating applications, which utilises generator-hyperledger-composer:
npm install -g yo


Step 2: Install Playground
If you've already tried Composer online, you'll have seen the browser app "Playground". You can run this locally on your development machine too, giving you a UI for viewing and demonstrating your business networks.

Browser app for simple editing and testing Business Networks:

npm install -g composer-playground

Step 3: Set up your IDE
Whilst the browser app can be used to work on your Business Network code, most users will prefer to work in an IDE. Our favourite is VSCode, because a Composer extension is available.

Install VSCode from this URL: https://code.visualstudio.com/download

Open VSCode, go to Extensions, then search for and install the Hyperledger Composer extension from the Marketplace.

Step 4: Install Hyperledger Fabric
This step gives you a local Hyperledger Fabric runtime to deploy your business networks to.

1. In a directory of your choice (we will assume ~/fabric-tools), get the .zip file that contains the tools to install Hyperledger Fabric:

mkdir ~/fabric-tools && cd ~/fabric-tools

curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip
unzip fabric-dev-servers.zip

A tar.gz is also available if you prefer: just replace the .zip file with fabric-dev-servers.tar.gz1 and the unzip command with a tar xvzf command in the above snippet.

2. Use the scripts you just downloaded and extracted to download a local Hyperledger Fabric runtime:

cd ~/fabric-tools
./downloadFabric.sh

Congratulations, you've now installed everything required for the typical Developer Environment. Read on to learn some of the most common things you'll do with this environment to develop and test your Blockchain Business Networks.

Controlling your dev environment

Starting and stopping Hyperledger Fabric
You control your runtime using a set of scripts which you'll find in ~/fabric-tools if you followed the suggested defaults.

The first time you start up a new runtime, you'll need to run the start script, then generate a PeerAdmin card:

cd ~/fabric-tools
./startFabric.sh
./createPeerAdminCard.sh

You can start and stop your runtime using ~/fabric-tools/stopFabric.sh, and start it again with ~/fabric-tools/startFabric.sh.

At the end of your development session, you run ~/fabric-tools/stopFabric.sh and then ~/fabric-tools/teardownFabric.sh. Note that if you've run the teardown script, the next time you start the runtime, you'll need to create a new PeerAdmin card just like you did on first time startup.

The local runtime is intended to be frequently started, stopped and torn down, for development use. If you're looking for a runtime with more persistent state, you'll want to run one outside of the dev environment, and deploy Business Networks to it. Examples of this include running it via Kubernetes, or on a managed platform such as IBM Cloud.

Start the web app ("Playground")
To start the web app, run:
composer-playground

It will typically open your browser automatically, at the following address: http://localhost:8080/login

You should see the PeerAdmin@hlfv1 Card you created with the createPeerAdminCard script on your "My Business Networks" screen in the web app: if you don't see this, you may not have correctly started up your runtime!

Congratulations, you've got all the components running, and you also know how to stop and tear them down when you're done with your dev session.

Appendix: destroy a previous setup

If you've previously used an older version of Hyperledger Composer and are now setting up a new install, you may want to kill and remove all previous Docker containers, which you can do with these commands:

    docker kill $(docker ps -q)
    docker rm $(docker ps -aq)
    docker rmi $(docker images dev-* -q)

Introduction to Hyperledger Composer - Typical Solution Architecture



Hyperledger Composer enables architects and developers to quickly create "full-stack" blockchain solutions. i.e. business logic that runs on the blockchain, REST APIs that expose the blockchain logic to web or mobile applications, as well as integrating the blockchain with existing enterprise systems of record.



Hyperledger Composer is composed of the following high-level components:
  • Execution Runtimes
  • JavaScript SDK
  • Command Line Interface
  • REST Server
  • LoopBack Connector
  • Playground Web User Interface
  • Yeoman code generator
  • VSCode and Atom editor plugins

Execution Runtimes
Hyperledger Composer has been designed to support different pluggable runtimes, and currently has three runtime implementations: 
* Hyperledger Fabric version 1.0. State is stored on the distributed ledger. 
* Web, which executes within a web page, and is used by Playground. State is stored in browser local storage. 
* Embedded, which executes within a Node.js process, and is used primarily for unit testing business logic. State is stored in an in-memory key-value store.

Connection Profiles

Connection Profiles are used across Hyperledger Composer to specify how to connect to an execution runtime. There are different configuration options for each type of execution runtime. For example, the connection profile for an Hyperledger Fabric version 1.0 runtime will contain the TCP/IP addresses and ports for the Fabric peers, as well as cryptographic certificates etc.

Connection Profiles are referred to by name (in both code and on the command line) and the connection profile documents (in JSON format) are resolved from the user's home directory.

JavaScript SDK
The Hyperledger Composer JavaScript SDK is a set of Node.js APIs the enables developers to create applications to manage and interact with deployed business networks.

The APIs are split between two npm modules:

1. composer-client used to submit transactions to a business network or to perform Create, Read, Update, Delete operations on assets and participants
2. composer-admin used to manage business networks (deploy, undeploy)
Details of all the APIs are available as JSDocs.

composer-client
This module would usually be installed as a local dependency of an application. It provides the API that is used by business applications to connect to a business network to access assets, participants and submitting transactions. When in production this is only module that needs to be added as a direct dependency of the application.

composer-admin
This module would usually be installed as a local dependency of administrative applications. This API permits the creation of and deployment of business network definitions.

Command Line Interface
The composer command line tool enables developers and administrators to deploy and managed business network definitions.

REST Server
The Hyperledger Composer REST Server automatically generates a Open API (Swagger) REST API for a business network. The REST Server (based on LoopBack technology) converts the Composer model for a business network into an Open API definition, and at runtime implements Create, Read, Update and Delete support for assets and participants and allows transactions to be submitted for processing or retrieved.

LoopBack Connector
The Hyperledger Composer LoopBack Connector is used by the Composer REST Server, however it may also be used standalone by integration tools that support LoopBack natively. Alternatively it may be used with the LoopBack tools to create more sophisticated customizations of the REST APIs.

Playground Web User Interface
Hyperledger Composer Playground is a web user interface to define and test business networks. It allows a business analyst to quickly import samples and prototype business logic that executes on the Web or Hyperledger Fabric runtime.

Yeoman Code Generators
Hyperledger Composer uses the Open Source Yeoman code generator framework to create skeleton projects:
  • Angular web application
  • Node.js application
  • Skeleton business network


VSCode and Atom Editor Extensions
Hyperledger Composer has community contributed editor extensions for VSCode and Atom. The VSCode extension is very powerful and validates Composer model and ACL files, providing syntax highlighting, error detection and snippets support. The Atom plugin is much more rudimentary and only has basic syntax highlighting.

Monday, June 4, 2018

Introduction to Hyperledger Composer - Key Concepts



Welcome to Hyperledger Composer

Hyperledger Composer is an extensive, open development toolset and framework to make developing blockchain applications easier. Our primary goal is to accelerate time to value, and make it easier to integrate your blockchain applications with the existing business systems. You can use Composer to rapidly develop use cases and deploy a blockchain solution in weeks rather than months. Composer allows you to model your business network and integrate existing systems and data with your blockchain applications.

Hyperledger Composer supports the existing Hyperledger Fabric blockchain infrastructure and runtime, which supports pluggable blockchain consensus protocols to ensure that transactions are validated according to policy by the designated business network participants.

Everyday applications can consume the data from business networks, providing end users with simple and controlled access points.

You can use Hyperledger Composer to quickly model your current business network, containing your existing assets and the transactions related to them; assets are tangible or intangible goods, services, or property. As part of your business network model, you define the transactions which can interact with assets. Business networks also include the participants who interact with them, each of which can be associated with a unique identity, across multiple business networks.



How does Hyperledger Composer work in practice?

For an example of a business network in action; a realtor can quickly model their business network as such:

Assets: houses and listings
Participants: buyers and homeowners
Transactions: buying or selling houses, and creating and closing listings
Participants can have their access to transactions restricted based on their role as either a buyer, seller, or realtor. The realtor can then create an application to present buyers and sellers with a simple user interface for viewing open listings and making offers. This business network could also be integrated with existing inventory system, adding new houses as assets and removing sold properties. Relevant other parties can be registered as participants, for example a land registry might interact with a buyer to transfer ownership of the land.

Key Concepts in Hyperledger Composer

Hyperledger Composer is a programming model containing a modeling language, and a set of APIs to quickly define and deploy business networks and applications that allow participants to send transactions that exchange assets.

Hyperledger Composer Components

You can experience Hyperledger Composer with our browser-based UI called Hyperledger Composer Playground. Playground is available as a hosted version (no install necessary) or a local install (good for editing and testing sample business networks offline).

Developers who want to use Hyperledger Composer's full application development capabilities should install the Developer Tools.

Key Concepts in Hyperledger Composer

Blockchain State Storage

All transactions submitted through a business network are stored on the blockchain ledger, and the current state of assets and participants are stored in the blockchain state database. The blockchain distributes the ledger and the state database across a set of peers and ensures that updates to the ledger and state database are consistent across all peers using a consensus algorithm.

Connection Profiles

Hyperledger Composer uses Connection Profiles to connect to a runtime. A Connection Profile is a JSON document that lives in the user's home directory (or may come from an environment variable) and is referenced by name when using the Composer APIs or the Command Line tools. Using connection profiles ensures that code and scripts are easily portable from one runtime instance to another. You can read more about Connection Profiles in the reference section.

Assets

Assets are tangible or intangible goods, services, or property, and are stored in registries. Assets can represent almost anything in a business network, for example, a house for sale, the sale listing, the land registry certificate for that house, and the insurance documents for that house may all be assets in one or more business networks.

Assets must have a unique identifier, but other than that, they can contain whatever properties you define. Assets may be related to other assets or participants.

Participants

Participants are members of a business network. They may own assets and submit transactions. Participant types are modeled, and like assets, must have an identifier and can have any other properties as required.

Identities and ID cards

Within a business network, participants can be associated with an identity. ID cards are a combination of an identity, a connection profile, and metadata. ID cards simplify the process of connecting to a business network, and extend the concept of an identity outside the business network to a 'wallet' of identities, each associated with a specific business network and connection profile.

Transactions

Transactions are the mechanism by which participants interact with assets. This could be as simple as a participant placing a bid on a asset in an auction, or an auctioneer marking an auction closed, automatically transferring ownership of the asset to the highest bidder.

Queries

Queries are used to return data about the blockchain world-state. Queries are defined within a business network, and can include variable parameters for simple customization. By using queries, data can be easily extracted from your blockchain network. Queries are sent by using the Hyperledger Composer API.

Events

Events are defined in the business network definition in the same way as assets or participants. Once events have been defined, they can be emitted by transaction processor functions to indicate to external systems that something of importance has happened to the ledger. Applications can subscribe to emitted events through the composer-client API.

Access Control

Business networks may contain a set of access control rules. Access control rules allow fine-grained control over what participants have access to what assets in the business network and under what conditions. The access control language is rich enough to capture sophisticated conditions declaratively, such as "only the owner of a vehicle can transfer ownership of the vehicle". Externalizing access control from transaction processor function logic makes it easier to inspect, debug, develop and maintain.

Historian registry

The historian is a specialised registry which records successful transactions, including the participants and identities that submitted them. The historian stores transactions as HistorianRecord assets, which are defined in the Hyperledger Composer system namespace.