Read this in other languages: 日本語
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:
- Buyer creates the order
- Seller contacts a provider for the items
- Shipper delivers the items
- Finance company processes payments to the seller
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:
- Develop a Node.js smart contract
- Package and deploy the smart contract to a local instance of Hyperledger Fabric using IBM Blockchain Platform Extension for VS Code
- Develop a Node.js blockchain web application to interact with the deployed Fabric network
Note: For deploying the smart contract to IBM Blockchain Platform (on IBM Cloud) instead, follow this code pattern.
The developer uses the IBM Blockchain Platform Extension for VS Code to:
- Package a smart contract.
- Launch a local Hyperledger Fabric Network.
- Install chaincode on the peer node.
- Instantiate the chaincode on the peer node.
- 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.
- IBM Blockchain Platform Extension for VS Code is designed to assist users in developing, testing, and deploying smart contracts -- including connecting to Hyperledger Fabric environments.
- Hyperledger Fabric v1.4 is a platform for distributed ledger solutions, underpinned by a modular architecture that delivers high degrees of confidentiality, resiliency, flexibility, and scalability.
- Visual Studio Code is a code editor that's redefined and optimized for building and debugging modern web and cloud applications.
- Node.js is an open source, cross-platform JavaScript run-time environment that executes server-side JavaScript code.
- Bootstrap is an open source toolkit for developing with HTML, CSS, and JavaScript.
Follow these steps to set up and run this code pattern. The steps are described in detail below.
You will need to follow the requirements for the IBM Blockchain Platform Extension for VS Code:
- VSCode version 1.38.0 or greater
- Node v8.x or v10.x and npm v6.x or greater
- Docker version v17.06.2-ce or greater
- Docker Compose v1.14.0 or greater
- Clone the repo
- Use the VS Code extension to set up a smart contract on a basic Fabric network
- Run the application
Clone this repository in a folder your choice:
git clone https://github.com/IBM/global-financing-blockchain.git
Open Visual Studio code and open the contract
folder.
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.
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.
- In the
FABRIC ENVIRONMENTS
section near the bottom, click onSmart Contracts
>Installed
>+ Install
. You will see a pop-up similar to the graphic below.
- Then select the packaged contract:
[email protected] Packaged
Note The 0.0.1 comes from yourpackage.json
line:"version": "0.0.1"
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
.
-
Under Smart Contracts you will see a section that says Instantiated. Click on
+ Instantiate
under it. -
The extension will then ask you which contract and version to instantiate — choose
[email protected] Installed
.
- The extension will then ask you which function to call on instantiate — type in
instantiate
- Next, it will ask you for the arguments to the function. There are none, so just hit enter.
- Next, the extension will then ask you do you want to use a provide a private data collection configuration file? - Click on
No
.
- Lastly, the extension will then ask you do you want to choose a smart contract endorsement policy. Choose
Default (single endorser, any org)
.
Once instantiation of the contract completes, you should get the message Successfully instantiated smart contract
and you should see [email protected]
under Instantiated
under FABRIC ENVIRONMENTS
.
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 [email protected]
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 '[email protected]'
. You can now see [email protected]
in the FABRIC WALLETS
section under Local Fabric 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 [email protected]
to the following location in the directory where you have cloned this repo:
/global-financing-blockchain/web-app/controller/restapi/features/fabric/_idwallet/[email protected]
Almost done, you can 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:
-
If you run into an error like this one:
error: [Remote.js]: Error: Failed to connect before the deadline URL:grpc://localhost:17051 error: [Network]: _initializeInternalChannel: Unable to initialize channel. Attempted to contact 1 Peers. Last error was Error: Failed to connect before the deadline URL:grpc://localhost:17051
This error has occurred because the ports used for the orderer/certificate authority/peer in the connection.json file are not the same as the ones specified as the default ports in the settings.json file for the IBM Blockchain Platform Extension for VSCode. You will need to update the ports in the connection.json file to match the ones specified in the settings.json file.
Click on the Gear symbol in the bottom left corner and select
Settings
. ExpandExtensions
in the left navigation pane in the newly opened "Settings" tab and selectBlockchain configuration
. Click onEdit in settings.json
to open the settings.json file for the Blockchain platform extension. You should see a file with contents like this:
{
"ibm-blockchain-platform.fabric.runtime": {
"ports": {
"orderer": 17053,
"peerRequest": 17057,
"peerChaincode": 17058,
"peerEventHub": 17059,
"certificateAuthority": 17060,
"couchDB": 17061,
"logs": 17062
},
"developmentMode": false
},
"ibm-blockchain-platform.fabric.wallets": [],
"ibm-blockchain-platform.fabric.gateways": []
}
Replace the orderer, peer and CA ports in the connection.json file for your project with the orderer
, peerRequest
and certificateAuthority
ports specified in this settings.json file.
This application can be expanded in a couple of ways:
- Create a wallet for every member and use the member's wallet to interact with the application.
- Update the application to interact through the IBM Blockchain Platform starter plan on IBM Cloud.
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.