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.0:

    export FABRIC_VERSION=hlfv1

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

Live analytics with an event store fed from Java and analyzed in Jupyter Notebook

Event-driven analytics requires a data management system that can scale to allow a high rate of incoming events while optimizing to allow immediate analytics. IBM Db2 Event Store extends Apache Spark to provide accelerated queries and lightning fast inserts. This code pattern is a simple introduction to get you started with event-driven analytics. You can...

Continue reading Live analytics with an event store fed from Java and analyzed in Jupyter Notebook

Blockchain: Why can’t this be done with a database?

Good question! In this post, I’ll try to answer it as succinctly as possible. I’ll start by defining the term “database,” and then look at several aspects of blockchain technology. For each aspect, I’ll ask the question, “Can this be done with a database?” First, allow me to define the terms. What is a “database”?...

Continue reading Blockchain: Why can’t this be done with a database?

Related Links

IBM Blockchain

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