Name: Decentralized-Energy-Composer
Owner: International Business Machines
Description: A decentralized energy network implementing Blockchain transactions using Hyperledger Composer
Created: 2017-07-19 20:46:17.0
Updated: 2018-01-17 18:57:17.0
Pushed: 2018-01-08 23:44:18.0
Homepage: https://developer.ibm.com/code/patterns/decentralized-energy-hyperledger-composer/
Size: 1970
Language: TypeScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Read this in other languages: ??.
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.
In this developer journey, we will create such a Blockchain application using Hyperledger Composer. 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.
Follow these steps to setup and run this developer journey. The steps are described in detail below.
npm install -g composer-cli
npm install -g composer-rest-server
npm install -g generator-hyperledger-composer
Clone the Decentralized-Energy-Composer code
locally. In a terminal, run:
git clone https://github.com/IBM/Decentralized-Energy-Composer
These commands will kill and remove all running containers, and should remove all previously created Hyperledger Fabric chaincode images:
er kill $(docker ps -q)
er rm $(docker ps -aq)
er rmi $(docker images dev-* -q)
Set Hyperledger Fabric version to v1.0:
export FABRIC_VERSION=hlfv1
All the scripts will be in the directory /fabric-tools
. Start fabric and create peer admin card:
abric-tools/
wnloadFabric.sh
artFabric.sh
eatePeerAdminCard.sh
Next generate the Business Network Archive (BNA) file from the root directory:
./
install
The composer archive create
command in package.json
has created a file called decentralized-energy-network.bna
in the dist
folder.
Now, we are ready to deploy the business network to Hyperledger Fabric. This requires the Hyperledger Composer chaincode to be installed on the peer,then the business network archive (.bna) must be sent to the peer, and a new participant, identity, and associated card must be created to be the network administrator. Finally, the network administrator business network card must be imported for use, and the network can then be pinged to check it is responding.
First, install the composer runtime:
ist/
oser runtime install --card PeerAdmin@hlfv1 --businessNetworkName decentralized-energy-network
Deploy the business network:
oser network start --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile decentralized-energy-network.bna --file networkadmin.card
Import the network administrator identity as a usable business network card:
oser card import --file networkadmin.card
Check that the business network has been deployed successfully, run the following command to ping the network:
oser network ping --card admin@decentralized-energy-network
First, go into the angular-app
folder and install the dependency:
./angular-app/
install
To start the application:
start
The application should now be running at:
http://localhost:4200
The REST server to communicate with network is available here:
http://localhost:3000/explorer/
Once the application opens, create participants and fill in dummy data. Create Residents, Banks and Utility Companies.
Execute transactions manually between Residents, Resident and Bank, and Resident and Utility Company. After executing transactions, ensure the participants account values are updated.
At the end of your session, stop fabric:
/fabric-tools
opFabric.sh
ardownFabric.sh
This application demonstrates a basic idea of a decentralized energy network using Blockchain and can be expanded in several ways: