IBM / global-financing-blockchain

A global finance application on blockchain developed using the IBM Blockchain Platform Extension for VS Code
https://developer.ibm.com/patterns/global-financing-use-case-for-blockchain/
Apache License 2.0
69 stars 73 forks source link
blockchain fabric-network hyperledger-fabric nodejs

Build Status

Read this in other languages: 日本語

Global financing with blockchain

The Global Finance application using blockchain technology tracks actions on an order by the various members of a network -- buyer, seller, provider, shipper, and finance company. These actions include:

This use case addresses dispute resolution and can be applied across industry verticals to resolve disputes. This use case is inspired by the RedBook tutorial by Bob Dill and uses the same application interface. This use case employs a Node.js smart contract and a Node.js web application.

The code pattern demonstrates how a Node.js smart contract can be packaged using the IBM Blockchain Platform Extension for VS Code. Then, using the extension, you can set up a local instance of the Hyperledger Fabric network, on which you can install and instantiate the contract. The Node.js web application can interact with the network using the 'fabric-network' sdk.

When you have completed this code pattern, you will understand how to:

Note: For deploying the smart contract to IBM Blockchain Platform (on IBM Cloud) instead, follow this code pattern.

Architecture flow

The developer uses the IBM Blockchain Platform Extension for VS Code to:

  1. Package a smart contract.
  2. Launch a local Hyperledger Fabric Network.
  3. Install chaincode on the peer node.
  4. Instantiate the chaincode on the peer node.
  5. Use a Global Finance application to interact with the Hyperledger Fabric network through API calls using the fabric-network npm library. Admins can also use the application to create new participants.

Included components

Featured technologies

Running the application

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

Prerequisites

You will need to follow the requirements for the IBM Blockchain Platform Extension for VS Code:

Steps

  1. Clone the repo
  2. Use the VS Code extension to set up a smart contract on a basic Fabric network
  3. Run the application

1. Clone the repo

Clone this repository in a folder your choice:

git clone https://github.com/IBM/global-financing-blockchain.git

2. Use the VS Code extension to set up a smart contract on a basic Fabric network

Open Visual Studio code and open the contract folder.

Package the smart contract

Press the F1 key to see the different VS code options. Choose IBM Blockchain Platform: Package Open Project.

Click the IBM Blockchain Platform extension button on the left. This will show the packaged contracts on top and the blockchain connections on the bottom.

Setup fabric locally

You should see FABRIC ENVIRONMENTS on the left side of the editor. Under this section, you should see Local Fabric. Click it to start the Local Fabric.

The extension will now provision the Docker containers that will act as nodes in your network. Once the provisioning is finished and the network is up and running, you will see the options to install and instantiate the smart contract, the Channels information, the Nodes and the organization msps under Organizations. You are now ready to install the smart contract.

Install and instantiate the smart contract

Install

After the install is complete, you should get a message Successfully installed on peer peer0.org1.example.com. You should also see that the contract is listed under Installed under FABRIC ENVIRONMENTS.

Instantiate

Once instantiation of the contract completes, you should get the message Successfully instantiated smart contract and you should see globalfinancing@0.0.1 under Instantiated under FABRIC ENVIRONMENTS.

Add Identity on CA Node

We will now create an identity using the CA (Certificate Authority) node. The identity information and key files are needed in order to authenticate and run the application.

Under FABRIC ENVIRONMENTS section in the left hand pane, expand Nodes and right click on ca.org1.example.com. Choose Create Identity (register and enroll).

Type User1@org1.example.com and press the enter key.

The extension will then ask if you want to add any attributes to this identity. Click on No.

Once the identity is successfully created, you should get the message Successfully created identity 'User1@org1.example.com'. You can now see User1@org1.example.com in the FABRIC WALLETS section under Local Fabric Wallet.

Export Wallet

Under FABRIC WALLETS, right click on Local Fabric Wallet and select Export Wallet.

You can save the exported files anywhere.

From the exported directory, copy the folder for User1@org1.example.com to the following location in the directory where you have cloned this repo:

  /global-financing-blockchain/web-app/controller/restapi/features/fabric/_idwallet/User1@org1.example.com

Almost done, you can run the application.

3. Run the application

In a new terminal, navigate to the web-app directory:

  cd global-financing-blockchain/web-app/

Build the node dependencies:

  npm install

Run the application:

  npm start

Unified member's view:

Troubleshooting

Extending the code pattern

This application can be expanded in a couple of ways:

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