This blog post is an article from a series of articles on the book published in December 2019 “Blockchain with SAP” (Rheinwerk publishing, Bonn, ISBN 978-3-8362-6914-8). This blog post concerns the eighth chapter of the book, which develops two example applications for MultiChain.

In the last blog post, we developed a simple pharmaceutical inventory based on MultiChain. This blog post concerns a more complex example to simulate a decentralized energy market, analogous to the same example which has already been implemented with Hyperledger Fabric.

This example is developed in MultiChain 1.0 and thus has no support for smart contracts – the business logic is therefore outsourced to a Node.js-based middleware. A SAPUI5-based frontend is displayed as a user interface. The architecture of the application thus corresponds to the known Model View Controller (MVC) design pattern:

  • the blockchain is the data model,
  • the Node.js middleware is the controller,
  • the SAPUI5 interface is the view.

A separate cryptocurrency

MultiChain supports the creation of separate cryptocurrencies which is used as part of this example. The generation of a separate cryptocurrency is achieved, basically out of nothing, by the initial transfer to a recipient address. With the following RPC call to the MultiChain, for example, 1000 virtual SAPCoins are sent to the address 17UFFkEkTvw5nGKA9sPXRWV75G2jd3m7GLuU7r:

{"method": "issue", "params":

["17UFFkEkTvw5nGKA9sPXRWV75G2jd3m7GLuU7r","SAPCoins",1000]}

 

It is possible to check in the node’s dashboard that the output was successful since the given address is that of the node:

(c) Rheinwerk Verlag

The node can further distribute these coins. This requires additional participants which are identified by recipient addresses.

Generating new recipient addresses

Generating new participants is the same as generating new recipient addresses. The corresponding calls are provided by the MultiChain API via RPC:

{"method":"getnewaddress", "params":[]}

 

This generates a new recipient address to which coins can be forwarded. We require four of these to simulate all planned participants.

Assignment of rights

The next step is the assignment of rights for each address for receiving and sending assets:

{"method":"grant",

"params":["14UsV3P5BHjbWP2aS6hRyrBRwc5VxLpsmeFCSd",

"connect,send,receive"]}

 

The above call assigns the rights to connect, send, and receive assets and thus our newly created cryptocurrency. The dashboard of the node confirms the assigned rights:

(c) Rheinwerk Verlag

Sending assets to an address

The call to send assets to a recipient address is “send” or “sendtoaddress”. The following call sends 50 coins from the executor’s account to the given address:

{"method":"sendasset", "params":[

"14UsV3P5BHjbWP2aS6hRyrBRwc5VxLpsmeFCSd", "SAPCoins", 50]}

This call enables coins to be distributed to the participants so that each has the same account balance for trading on the decentralized energy market.

Decentralized energy market

The decentralized energy market again simulates the buying and selling of electricity offers. Since the participants on the energy market are again only simulated and do not actually exist, a file called user.json is predefined which contains the information of the users in the form of a list of JSON objects which represent the users.

An entry looks as follows and, in addition to the user ID to identify the participant, also contains his address as well as his cryptographic key, which is required for sending assets, i.e. for paying:

[{

"userId": "fredrika93ozumv",

"userName": "Fredrika Riley",

"openingBalance": 50000,

"address": "1FdJ7JFdwcnstM8zwGgQkAx9SQVR6FJnNPqyxH",

"pubkey": "030011d430958661c39a4c95927f6a348b61c6a

f54a6285e7d68a6f9f21a412922",

"privkey": "VEY9nFQwGoXXJAk7CrH3B1fchdyKA9Fvo9bkDoLV

hNXVescwDoAza13z"

},

…

]

 

This file is read in when starting the software, and the objects are updated by the middleware at runtime and, if required, forwarded to the frontend for display.

Checking account balances

The command “getaddressbalances” enables the participants’ account balances in the blockchain to be checked. A list of addresses for which information is to be provided is specified as a parameter:

{"method":"getaddressbalances", "params":[

"14UsV3P5BHjbWP2aS6hRyrBRwc5VxLpsmeFCSd"]}

Stream in the blockchain

The participants’ offers and the assets are managed in the blockchain. To do this, a separate stream called “EnergyMarket” is first of all set up to store the data there. The existence of the stream in the blockchain is the clue that the platform has already run once and has been correctly set up. If the stream is missing, it must first be set up and the initial credit and rights must be assigned to the participants.

The node.JS middleware

The middleware has greater significance in this project, as it must take on many tasks which would normally be handled by the smart contracts in the blockchain. For example, it checks whether the blockchain has already been correctly set up and, if required, corrects it. It also manages the profiles of participants, assigns the initial asset to it and assigns rights to it for sending and receiving assets. It checks purchases and sales of participants, and then forwards this to the blockchain, which receives the actual transactions for the sending and receiving of coins.

The major difference in this example is that the participants of the energy market have an actual cryptocurrency which is managed via the blockchain.

The SAPUI5 interface

The SAPUI5 interface is no different to the version with Hyperledger Fabric, and speaks to the middleware for data query which in turn queries the blockchain. The offers created by the participants are saved in the blockchain and their status attribute shows whether or not the product was purchased.

More articles of this series can be found here:

Wollen Sie mehr zur SAP Cloud Platform und der Funktionsweise der Blockchains erfahren? In unserem Buch „Blockchain mit SAP“ erläutern wir Ihnen ausführlich die Funktionsweise und demonstrieren Ihnen anhand zahlreicher Beispiele die Vorzüge dieser innovativen Technologie. Eine ausführliche Leseprobe zum Buch stellt der Verlag online bereit.

Would you like to find out more about the possibilities of MultiChain for your company? Our book “Blockchain with SAP” gives a detailed explanation of the advantages of MultiChain-based blockchain solutions. A detailed extract from the book is available online from the publisher.

Recommended articles

Data & Analytics

Accelerating SAP S/4HANA Migration with AI and Automation

In this blog post, we dive deeper into data migration, from the challenges faced by organizations to the advanced solutions offered …

read more
Logistics

How to Manage your Warehouse Dock in Real-time

Uncontrolled truck arrivals are typical for many loadings or unloading stations. The result: demurrage costs, bad dock utilization, and process waste. …

read more
Logistics

Supply Chain Design: The Effects of COVID-19

Many businesses are looking for an approach to master the challenges of the COVID-19 pandemic and make their supply chain network …

read more

Reimagine your Value Chain with us

Contact us