IBM / fabcar-blockchain-sample

Use a Kubernetes cluster to deploy a Fabric network smart contract onto blockchain
https://developer.ibm.com/patterns/write-a-smart-contract-for-the-fabcarcommercial-paper-or-iks-cluster-with-saas-v2-beta-network-think/
Apache License 2.0
107 stars 85 forks source link
blockchain containers fabric hyperledger kubernetes

日本語はこちら - Japanese version

Build Status

FabCar Blockchain Sample

Hyperledger Fabric sample Fabcar on IBM Blockchain Platform

NOTE: This developer pattern creates a blockchain network on IBM Blockchain Platform version 2.5 using the Hyperledger Fabric version 1.4.

This code pattern demonstrates setting up a network on the IBM Blockchain Platform and deploying the Fabcar smart contract on the network. Next, we setup our application to interact with the network including identities to submit transactions on the smart contract. The application is setup with a Node.js server using the Fabric Node SDK to process requests to the network, and an Angular client to bring up a web interface.

When the reader has completed this code pattern, they will understand how to:

Architecture flow

  1. The Blockchain Operator sets up the IBM Blockchain Platform service.
  2. The IBM Blockchain Platform enables to create a Hyperledger Fabric network onto a IBM Cloud Kubernetes Service, allowing to install and instantiate the Fabcar smart contract on the network.
  3. The Node.js application server uses the Fabric SDK to interact with the deployed network on IBM Blockchain Platform and creates APIs for a web client.
  4. The Angular client uses the Node.js application API to interact with the network.
  5. The User interacts with the Fabcar Angular web interface to update and query the blockchain ledger and state.

Included components

Featured technologies

Prerequisites

Running the application

Follow these steps to set up and run this code pattern. The steps are described in detail below.

Steps

To run a local network, you can find steps here

  1. Clone the repo
  2. Package the smart contract
  3. Create IBM Cloud services
  4. Build a network
  5. Deploy FabCar Smart Contract on the network
  6. Connect application to the network
  7. Run the application

1. Clone the repo

Clone this repository in a folder your choice:

git clone https://github.com/IBM/fabcar-blockchain-sample.git
cd fabcar-blockchain-sample

2. Package the smart contract

We will use the IBM Blockchain Platform extension on VS Code to package the Fabcar smart contract.

Now, we will start setting up the different services required for configuring our Hyperledger Fabric network on the IBM Cloud and for running our application using this network.

3. Create IBM Cloud services







4. Build a network

We will build a network as provided by the IBM Blockchain Platform documentation. This will include creating a channel with a single peer organization with its own MSP and CA (Certificate Authority), and an orderer organization with its own MSP and CA. We will create the respective identities to deploy peers and operate nodes.

Create your peer organization CA



Associate the peer organization CA admin identity



Use peer organization CA to register the peer and org1 admin identities



Create the peer organization MSP definition



Create a peer



Create your orderer organization CA



Associate the orderer organization CA admin identity



Use orderer organization CA to register orderer and orderer admin identities



Create the orderer organization MSP definition



Create an orderer



Add organization as Consortium Member on the orderer to transact



Create the channel



Join your peer to the channel



5. Deploy FabCar Smart Contract on the network

Install a smart contract



Instantiate smart contract



6. Connect application to the network

Connect with sdk through connection profile



Create an application admin



Update application connection profile

the current default contents of the config.json are to connect to a local fabric instance from VS Code.

After the updates, the contents of the config.json should look similar to the file shown below:

{
    "connection_file": "Org1MSP_profile.json",
    "appAdmin": "app-admin",
    "appAdminSecret": "app-adminpw",
    "orgMSPID": "Org1MSP",
    "caName": "169.46.208.151:30404",
    "userName": "user1",
    "gatewayDiscovery": { "enabled": true, "asLocalhost": false }
}

7. Run the application

Enroll admin

Register User

Deregister User

NOTE: The following steps need to be performed only if you wish to revoke an existing user.

By default, removal of identities is disabled in IBM Blockchain Platform. If you wish to remove identities, you need to manually override this default setting in the IBM Blockchain Platform console.



The removal of identities will now be enabled. As long as your application admin has been created with the hf.Revoker attribute set to the value of true (as specified in the Create an application admin step above, you can use the deregisterUser.js script to remove the user identity.

Start the application server

Start the web client

You can find the app running at http://localhost:4200/



You can go to the IBM Blockchain Platform console to monitor your users and get information on your channel including the blocks added.



Troubleshooting

update it as shown in the image below:



Links

License

This code pattern is licensed under the Apache Software License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ