decentralized-energy-fabric-on-IBP20

所属分类:区块链开发
开发工具:JavaScript
文件大小:1344KB
下载次数:0
上传日期:2023-01-07 17:57:06
上 传 者sh-1993
说明:  去中心化能源制造-IBP20,在IBM区块链平台上建立网络,并在网络上部署去中心化的能源智能合约。
(decentralized-energy-fabric-on-IBP20,Set up a network on the IBM Blockchain Platform and deploy a decentralized energy smart contract on the network.)

文件列表:
.travis.yml (249, 2020-05-07)
CONTRIBUTING.md (568, 2020-05-07)
LICENSE (11325, 2020-05-07)
MAINTAINERS.md (3269, 2020-05-07)
application-ts (0, 2020-05-07)
application-ts\_idwallet (0, 2020-05-07)
application-ts\_idwallet\User1@org1.example.com (0, 2020-05-07)
application-ts\_idwallet\User1@org1.example.com\User1@org1.example.com (1037, 2020-05-07)
application-ts\_idwallet\User1@org1.example.com\c75bd6911aca808941c3557ee7c97e90f3952e379497dc55eb903f31b50abc83-priv (246, 2020-05-07)
application-ts\_idwallet\User1@org1.example.com\c75bd6911aca808941c3557ee7c97e90f3952e379497dc55eb903f31b50abc83-pub (182, 2020-05-07)
application-ts\_idwallet\user1 (0, 2020-05-07)
application-ts\_idwallet\user1\ef02a426bd11a738d34e9e06a222aea0f5a25fa2398f07b5295ef18273adf415-priv (246, 2020-05-07)
application-ts\_idwallet\user1\ef02a426bd11a738d34e9e06a222aea0f5a25fa2398f07b5295ef18273adf415-pub (182, 2020-05-07)
application-ts\_idwallet\user1\user1 (1180, 2020-05-07)
application-ts\connection.json (1160, 2020-05-07)
application-ts\package-lock.json (167486, 2020-05-07)
application-ts\package.json (1553, 2020-05-07)
application-ts\src (0, 2020-05-07)
application-ts\src\application.js (10423, 2020-05-07)
application-ts\src\application.ts (5780, 2020-05-07)
application (0, 2020-05-07)
application\.eslintignore (52, 2020-05-07)
application\.eslintrc.js (899, 2020-05-07)
application\add-participants (0, 2020-05-07)
application\add-participants\addBank.js (3232, 2020-05-07)
application\add-participants\addResident.js (3348, 2020-05-07)
application\add-participants\addUtilityCompany.js (3317, 2020-05-07)
application\add-participants\registerBank.js (2760, 2020-05-07)
application\add-participants\registerResident.js (2760, 2020-05-07)
application\add-participants\registerUtilityCompany.js (2760, 2020-05-07)
application\application.js (5655, 2020-05-07)
application\config.json (379, 2020-05-07)
application\connection.json (1160, 2020-05-07)
application\enrollAdmin.js (2121, 2020-05-07)
application\invoker-tx (0, 2020-05-07)
application\invoker-tx\cash-trade.js (2637, 2020-05-07)
application\invoker-tx\energy-trade.js (2660, 2020-05-07)
... ...

[![Build Status](https://travis-ci.org/IBM/Decentralized-energy-fabric-on-IBP20.svg?branch=master)](https://travis-ci.org/IBM/Decentralized-energy-fabric-on-IBP20) # Decentralized Energy with IBM Blockchain Platform >Hyperledger Fabric sample Decentralized Energy on IBM Blockchain Platform This code pattern demonstrates setting up a network on the IBM Blockchain Platform and deploying the Decentralized smart contract on the network. Next, we generate client-side certificates so the developer can subsequently enroll an application identity and then 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. A key application of Blockchain being currently explored is a Decentralized Energy network. The idea stems from a neighborhood where certain Residents are producing energy through Solar panels or other means, and can sell excess energy to Residents needing energy. The transactions would be based on coins in each Resident's account. As per a pre-determined contract and rate, the coins would be debited from the consumer and credited to the producer, for a certain billing period. Each transaction would need to be atomic and added to a Blockchain ledger for trust and verification. The network can include Banks to transact coins for Fiat currency (USD). The network can have Utility Company who can buy or provide energy through the network. The network consists of Residents, Banks and Utility Companies. Residents can exchange coins for energy among each other. The application assumes a pre-paid system where transactions occur after the energy is consumed and the values are updated. The Resident can exchange coins for Fiat money (USD) with Banks on the network. The Residents can also transact coins for energy with a Utility company on the network. 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. Lastly, the application is setup with a Node.js server using the Fabric Node SDK to process transactions that communicate with the network. When you have completed this code pattern, you will understand how to: * Package the smart contract using IBM Blockchain Platform Extension for VS Code * Setup a Hyperledger Fabric network on IBM Blockchain Platform * Install and instantiate smart contract package onto the IBM Blockchain Platform * Develop a Node.js server with the Hyperledger Fabric SDK to interact with the deployed network * Interact with the contract and execute transactions using the SDK. # Architecture flow

1. The Blockchain Operator clones the GitHub repo with the Decentralized Energy smart contract. 2. The Blockchain Operator uses the IBM Blockchain VSCode Extension to package the smart contract. 3. The Blockchain Operator creates a IBM Blockchain Platform 2Install chaincode on the peer node. 4. The IBM Blockchain Platform creates a Hyperledger Fabric network onto a IBM Cloud Kubernetes Service, enabling us to install and instantiate the Decentralized Energy smart contract on the network. 5. The Decentralized Energy web app uses the Hyperledger Fabric Node.js SDK to submit transactions to the Hyperledger Fabric network running on IBM Cloud. 6. The Residents, Banks, and Utility Companies interact with the Decentralized Energy web-app and all transaction details are saved onto the IBM Blockchain Platform, unbeknown to the end-user. # Included components * [IBM Blockchain Platform](https://www.ibm.com/cloud/blockchain-platform) Gives you total control of your blockchain network with a user interface that can simplify and accelerate your journey to deploy and manage blockchain components on the IBM Cloud Kubernetes Service. * [IBM Cloud Kubernetes Service](https://www.ibm.com/cloud/container-service) Creates a cluster of compute hosts and deploys highly available containers. A Kubernetes cluster lets you securely manage the resources that you need to quickly deploy, update, and scale applications. * [IBM Blockchain Platform Extension for VS Code](https://marketplace.visualstudio.com/items?itemName=IBMBlockchain.ibm-blockchain-platform) Designed to assist users in developing, testing, and deploying smart contracts -- including connecting to Hyperledger Fabric environments. ## Featured technologies + [Hyperledger Fabric v1.4](https://hyperledger-fabric.readthedocs.io) is a platform for distributed ledger solutions, underpinned by a modular architecture that delivers high degrees of confidentiality, resiliency, flexibility, and scalability. + [Node.js](https://nodejs.org) is an open source, cross-platform JavaScript run-time environment that executes server-side JavaScript code. ### Prerequisites * [IBM Cloud account](https://cloud.ibm.com/registration/?target=%2Fdashboard%2Fapps) * [Node v8.x or v10.x and npm v6.x or greater](https://nodejs.org/en/download/) * [VSCode version 1.38.0 or greater](https://code.visualstudio.com) * [IBM Blockchain Platform Extension for VSCode](https://marketplace.visualstudio.com/items?itemName=IBMBlockchain.ibm-blockchain-platform) # Running the application Follow these steps to set up and run this code pattern. The steps are described in detail below. ### Steps 1. [Clone the repo](#1-clone-the-repo) 2. [Package the smart contract](#2-package-the-smart-contract) 3. [Create IBM Cloud services](#3-create-ibm-cloud-services) 4. [Build a network](#4-build-a-network) 5. [Deploy Decentralized Energy Smart Contract on the network](#5-deploy-decentralized-energy-smart-contract-on-the-network) 6. [Connect application to the network](#6-connect-application-to-the-network) 7. [Run the application](#7-run-the-application) ## 1. Clone the repo Clone this repository in a folder your choice: ``` git clone https://github.com/IBM/decentralized-energy-fabric-on-IBP20 ``` ## 2. Package the smart contract We will use the IBM Blockchain Platform extension to package the smart contract. * Open Visual Studio code and open the `contract` folder from Decentralized Energy repository that was cloned earlier. * 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.

* Next, right click on the packaged contract (in this case, select decentralized-energy@0.0.1) to export it and choose `Export Package`. * Choose a location on your machine and save `.cds` file. We will deploy this smart contract package on the IBM Blockchain Platform service in a later step. Now, we will start creating our Hyperledger Fabric network on the IBM Cloud. ## 3. Create IBM Cloud services * Create the [IBM Cloud Kubernetes Service](https://cloud.ibm.com/kubernetes/catalog/cluster). You can find the service in the `Catalog`. For this code pattern, we can use the `Free` cluster, and give it a name. Note, that the IBM Cloud allows one instance of a free cluster which expires after 30 days. **Note: it could take 20 minutes for the IBM Cloud Kubernetes Service setup to complete**.


* Create the [IBM Blockchain Platform](https://cloud.ibm.com/catalog/services/blockchain-platform) service on the IBM Cloud. You can find the service in the `Catalog`, and give it a name.


* After your kubernetes cluster is up and running, you can deploy your IBM Blockchain Platform on the cluster. Again - wait for the IBM Cloud Kubernetes service to indicate it was deployed. The IBM Blockchain Platform service walks through few steps and finds your cluster on the IBM Cloud to deploy the service on.


* Once the Blockchain Platform is deployed on the Kubernetes cluster, you can launch the console to start configuring your blockchain network. ## 4. Build a network We will build a network as provided by the IBM Blockchain Platform [documentation](https://cloud.ibm.com/docs/services/blockchain/howto?topic=blockchain-ibp-console-build-network#ibp-console-build-network). 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 - Navigate to the Nodes tab in the left navigation and click Add Certificate Authority. - Click Create an IBM Cloud Certificate Authority and Next. - Give it a CA display name of `Org1 CA` and click Next. - Specify an CA Administrator Enroll ID of `admin` and CA Administrator Enroll Secret of `adminpw`, then click Next. - Review the summary and click Add Certificate Authority.


#### Associate the peer organization CA admin identity - In the Nodes tab, select the Org1 CA once it is running (indicated by the green box in the tile). - Click Associate identity on the CA overview panel. - On the side panel, select Enroll ID. - Provide an Enroll ID of `admin` and an Enroll secret of `adminpw`. Use the default value of `Org1 CA Identity` for the Identity display name. - Click Associate identity to add the identity into your wallet and associate the admin identity with the Org1 CA.


#### Use peer organization CA to register the peer and org1 admin identities - Select the Org1 CA Certificate Authority and ensure the `admin` identity that was created for the CA is visible in the table. - We will register an admin for our organization "org1". Click on the Register User button. Give an Enroll ID of `org1admin`, and Enroll Secret of `org1adminpw`. Set the Type for this identity as `client`. We can specify to Use root affiliation or uncheck this field and select from any of the affiliated organizations from the drop-down list. We will leave the Maximum enrollments field blank. Click Next. - We will not be adding any attributes to this user. Click Register user. - We will repeat the process to create an identity of the peer. Click on the Register User button. Give an Enroll ID of `peer1`, and Enroll Secret of `peer1pw`. Set the Type for this identity as `peer`. We can specify to Use root affiliation or uncheck this field and select from any of the affiliated organizations from the drop-down list. Click Next. - We will not be adding any attributes to this user. Click Register user.


#### Create the peer organization MSP definition - Navigate to the Organizations tab in the left navigation and click Create MSP definition. - Enter the MSP Display name as `Org1MSP` and an MSP ID of `Org1MSP`. - Under Root Certificate Authority details, specify the peer CA that we created `Org1 CA` as the root CA for the organization. - Give the Enroll ID and Enroll secret for your organization admin, `org1admin` and `org1adminpw`. Then, give the Identity name as `Org1 Admin`. - Click the Generate button to enroll this identity as the admin of your organization and export the identity to the wallet. Click Export to export the admin certificates to your file system. Finally click Create MSP definition.


#### Create a peer - Navigate to the Nodes tab in the left navigation and click Add peer. - Click Create an IBM Cloud peer and then click Next. - Give the Peer display name as `Peer Org1` and click Next. - On the next screen, select `Org1 CA` as the Certificate Authority. Then, give the Peer enroll ID and Peer enroll secret for the peer identity that you created for your peer, that is, `peer1`, and `peer1pw`. Select the Organization MSP as `Org1MSP`, from the drop-down list. Leave the TLS CSR hostname blank. Click Next. - The next step is to Associate an identity with this peer to make it the admin of your peer. Select your peer admin identity `Org1 Admin` and click Next. - Review the summary and click Add peer.


#### Create your orderer organization CA - Navigate to the Nodes tab in the left navigation and click Add Certificate Authority. - Click Create an IBM Cloud Certificate Authority and Next. - Give it a CA display name of `Orderer CA` and click Next. - Specify an CA Administrator Enroll ID of `admin` and CA Administrator Enroll Secret of `adminpw`, then click Next. - Review the summary and click Add Certificate Authority.


#### Associate the orderer organization CA admin identity - In the Nodes tab, select the Orderer CA once it is running (indicated by the green box in the tile). - Click Associate identity on the CA overview panel. - On the side panel, select Enroll ID. - Provide an Enroll ID of `admin` and an Enroll secret of `adminpw`. Use the default value of `Orderer CA Identity` for the Identity display name. - Click Associate identity to add the identity into your wallet and associate the admin identity with the Orderer CA.


#### Use orderer organization CA to register orderer and orderer admin identities - Select the Orderer CA Certificate Authority and ensure the `admin` identity that was created for the CA is visible in the table. - We will register an admin for the "orderer" organization. Click on the Register User button. Give an Enroll ID of `ordereradmin`, and Enroll Secret of `ordereradminpw`. Set the Type for this identity as `client`. We can specify to Use root affiliation or uncheck this field and select from any of the affiliated organizations from the drop-down list. We will leave the Maximum enrollments field blank. Click Next. - We will not be adding any attributes to this user. Click Register user. - We will repeat the process to create an identity of the orderer. Click on the Register User button. Give an Enroll ID of `orderer1`, and Enroll Secret of `orderer1pw`. Set the Type for this identity as `orderer`. We can specify to Use root affiliation or uncheck this field and select from any of the affiliated organizations from the drop-down list. Click Next. - We will not be adding any attributes to this user. Click Register user.


#### Create the orderer organization MSP definition - Navigate to the Organizations tab in the left navigation and click Create MSP definition. - Enter the MSP Display name as `OrdererMSP` and an MSP ID of `OrdererMSP`. - Under Root Certificate Authority details, specify the peer CA that we created `Orderer CA` as the root CA for the organization. - Give the Enroll ID and Enroll secret for your organization admin, `ordereradmin` and `ordereradminpw`. Then, give the Identity name as `Orderer Admin`. - Click the Generate button to enroll this identity as the admin of your organization and export the identity to the wallet. Click Export to export the admin certificates to your file system. Finally click Create MSP definition.


#### Create an orderer - Navigate to the Nodes tab in the left navigation and click Add ordering service. - Click Create an IBM Cloud Ordering service and then click Next. - Give the Ordering service display name as `Orderer` and click Next. - On the next screen, select `Orderer CA` as the Certificate Authority. Then, give the Ordering service enroll ID and Ordering service enroll secret for the peer identity that you created for your orderer, that is, `orderer1`, and `orderer1pw`. Select the Organization MSP as `OrdererMSP`, from the drop-down list. Leave the TLS CSR hostname blank. Click Next. - The next step is to Associate an identity with this peer to make it the admin of your peer. Select your peer admin identity `Orderer Admin` and click Next. - Review the summary and click Add ordering service.


#### Add organization as Consortium Member on the orderer to transact - Navigate to the Nodes tab, and click on the Orderer that we created. - Under Consortium Members, click Add organization. - From the drop-down list, select `Org1MSP`, as this is the MSP that represents the peer's organization "Org1". - Click Add organization.


#### Create the channel - Navigate to the Channels tab in the left navigation and click Create channel. - Give the Channel name as `mychannel`. - Select the orderer you created, `Orderer` from the Ordering service drop-dow ... ...

近期下载者

相关文件


收藏者