RTP Kubernetes meetup features two interesting topics: how to deploy blockchain on Kubernetes and how to manage issues in Kubernetes.
Decentralized energy with Hyperledger Composer
Create a blockchain app to display and interact with a network through a web interface
Wondering where blockchain might apply in your own life? Interested in energy, sustainability, or climate change? Try your hand at creating a basic blockchain app to interact with a decentralized energy network! The idea behind the app is a neighborhood where residents produce and sell excess solar-panel energy to residents who need it. This is an excellent example of how blockchain can begin to transform our world.
A great way to start experimenting with blockchain is to model a network and build a blockchain application using the Hyperledger Composer toolset. In this pattern, the application presents a decentralized energy network where neighborhood residents who are producing energy through solar panels or other means can sell excess energy to fellow residents or utility companies.
Here’s how it works: The application allows the user to create network participants with account balances who can exchange coins for energy shared. (The network also includes banks to exchange cash for coins.) Transactions can be between residents, between resident and bank, or between resident and utility company. The application updates balances for each transaction, and each transaction is added to a blockchain ledger for trust and verification.
Once you create the application, you can expand it in several ways. For example, you can add specific permissions and participant access, set up real-time transactions among participants, and even integrate with IoT to read from power meters and distribute energy.
- Administrator interacts with decentralized energy UI comprising Angular framework.
- Application processes user requests to the network through a REST API.
- Requests are implemented to the blockchain state database on Hyperledger Fabric v1.
- REST API is used to retrieve the state of the database.
- Angular framework gets data through GET calls to the REST API.
To get started, all you need is Docker, npm, Node, Hyperledger Fabric, and Hyperledger Composer. (See the README for version notes.)
Then follow these 7 basic steps to create the network, start the application, and run energy-sharing transactions on the network:
- Clone the repo
Clone the Decentralized-Energy-Composer code locally:
git clone https://github.com/IBM/Decentralized-Energy-Composer
- Set up Hyperledger Fabric
Kill and remove any running containers or previously created Hyperledger Fabric chaincode images:
docker kill $(docker ps -q) docker rm $(docker ps -aq) docker rmi $(docker images dev-* -q)
Set the Hyperledger Fabric version to v1.0:
All the scripts are in /fabric-tools. Start Fabric and create the profile:
cd fabric-tools/ ./downloadFabric.sh ./startFabric.sh ./createPeerAdminCard.sh
- Generate the Business Network Archive (BNA)
Generate the BNA file from the root directory:
cd ../ npm install composer archive create -a dist/decentralized-energy-network.bna --sourceType dir --sourceName .
The composer archive create command creates a file called decentralized-energy-network.bna in the dist folder.
- Deploy to Fabric
Deploy the BNA file to Hyperledger Fabric:
First, install the composer runtime:
cd dist/ composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName decentralized-energy-network
Deploy the business network:
composer 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:
composer card import --file networkadmin.card
Check that the business network has been deployed successfully, run the following command to ping the network:
composer network ping --card admin@decentralized-energy-network
- Run the application
Go into the angular-app folder and install the dependency:
cd ../angular-app/ npm install
To start the application:
The application should now be running at: http://localhost:4200
The REST server to communicate with network is available here: http://localhost:3000/explorer/
- Create participants
Once the application opens, create participants and fill in dummy data. Create Residents, Banks, and Utility Companies.
- Execute transactions
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:
cd ~/fabric-tools ./stopFabric.sh ./teardownFabric.sh