Decentralized energy with Hyperledger Composer  

Create a blockchain app to display and interact with a network through a web interface

Last updated | By Raheel Zubairy


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.


  1. Administrator interacts with decentralized energy UI comprising Angular framework.
  2. Application processes user requests to the network through a REST API.
  3. Requests are implemented to the blockchain state database on Hyperledger Fabric v1.
  4. REST API is used to retrieve the state of the database.
  5. 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:

  1. Clone the repo

    Clone the Decentralized-Energy-Composer code locally:

    git clone
  2. 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.1:

    export FABRIC_VERSION=hlfv11

    All the scripts are in /fabric-tools. Start Fabric and create the profile:

    cd fabric-tools/ ./ ./ ./
  3. 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.

  4. Deploy to Fabric

    Deploy the BNA file to Hyperledger Fabric:

    First, install the composer runtime:

    cd dist/ composer network 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
  5. Run the application

    Go into the angular-app folder and install the dependency:

    cd ../angular-app/ npm install

    To start the application:

    npm 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/

  6. Create participants

    Once the application opens, create participants and fill in dummy data. Create Residents, Banks, and Utility Companies.

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

Related Blogs

Transformation everywhere – IBM Code at CEBIT 2018

As you may already know, 2018 was a pivotal year for CEBIT for many reasons. The fair has undergone a complete makeover; you would hardly recognize it. After almost 50 years, the expo not only changed its name by capitalising every letter (CeBIT has transformed to become CEBIT), it also changed its scheduling, opting for...

Continue reading Transformation everywhere – IBM Code at CEBIT 2018

Apps without privacy issues: Creating a blockchain wellness app on the cloud

Kubecoin takes fitness data directly from the phone health kit and places transactions on the "Kubechain." The app works anonymously and assigns a made-up identity to you, along with a randomly generated avatar. Your data can’t be traced to you, but you'll be able to see where your assigned avatar ranks on our leaderboard.

Continue reading Apps without privacy issues: Creating a blockchain wellness app on the cloud

Related Links

IBM Blockchain

Learn about blockchain basics, explore use cases, find tutorials, sample code, and blogs, and check out IBM solutions.