Git Product home page Git Product logo

global-financing-blockchain's Introduction

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:

  • 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.

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

  • 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.

Featured technologies

  • 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.

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

  • In the FABRIC ENVIRONMENTS section near the bottom, click on Smart 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 your package.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.

Instantiate

  • 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.

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 [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.

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 [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.

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

  • 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. Expand Extensions in the left navigation pane in the newly opened "Settings" tab and select Blockchain configuration. Click on Edit 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.

Extending the code pattern

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.

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

global-financing-blockchain's People

Contributors

cryptocomets avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.