Leveraging Stellar for Settling transactions on Hyperledger Fabric network — Part 1

Sachin Jha
Coinmonks
Published in
5 min readSep 24, 2018

--

What are Hyperledger Fabric and Stellar ?

Hyperledger Fabric, is a private, permissioned blockchain network technology which has become quite popular and is being used in a number of production networks, looking to create a shared ledger or a common view of digital assets representing real world physical assets, and the transactions related to them. If you want to read more, you can start with the official page.

To setup a network and install sample smart contracts you can also look at the IBM Blockchain Platform’s Starter plan. First time users can also get a credit of 500$ to explore the platform. Details available on the above link.

Stellar, is a public, permissionless distributed ledger technology which facilitates low cost payments, leveraging the native crypto currency Lumens(XLM) or digital assets, issued by different Anchors (participating organizations, which issue digital assets ).

While any organization like an MTO, or a bank or even an individual can become an anchor and issue assets, which are like IOUs, the assets will not be used for trade until the involved parties trust the issuer of the asset and its ability to honour the IOUs.

While these assets can be anything, most of the times, they represent cash deposits, that the anchor maintains in a given fiat currency. Such an asset is often referred as ‘stablecoin’, since it’s value is pegged to a fiat currency, like USD, EUR, etc which would usually have much little fluctuation as compared to cryptocurrencies.

Stellar also provides a distributed exchange to facilitate trades in the anchored assets and Lumens. Another important attribute of Stellar is that while any one can join the network, financial organizations can choose to transact with, specific organizations whom they trust and can obtain proof of the AML checks performed by the organization, before on boarding an end user as their customer.

So its not a disinter-mediating technology and allows banks and financial institutions to work within the regulatory frameworks, while making the payments process more efficient for their customers.

A case for Integration between Hyperledger Fabric and Stellar:

Hyperledger Fabric is a private network and so if there are transactions which require a proof of payment before the asset can be transferred, it’s not a straightforward process. There are few options as listed below

  1. In the smart contract, create an asset definition for <Contract>Coin or <Contract>Token e.g. for a smart contract dealing with Energy exahange the asset can be called ‘EnergyCoin’. Have one or more banks as part of the network and let them act as token issuers. The banks can help convert real currency and issue equivalent amount of tokens on the network, to a participant and vice versa. But the problem with this approach is that the token is restricted to this network alone and the bank needs to be involved ,every time a participant wants to convert the token into real cash and use it somewhere else.
  2. Another approach is to use a public network like Stellar in the following way:

a) to use a public network like stellar to make the payments against data stored and agreed upon on the hyperledger fabric network

b) Verify that the payment has been made by invoking the stellar APIs in fabric smart contract and then complete the asset transfer as agreed upon in fabric network.

With this approach, the tokens received, via payments on Stellar network can be deployed to use, as deemed fit. Moreover, with federally insured, stable coins such as the Stronghold USD, available these days, end users can transact in these digital assets on Stellar with much more confidence.

How to achieve this integration between Hyperledger Fabric and Stellar ?

At a high level :

a)Stellar provides sdks as well as REST APIs to interact with the network.

b)All transactions need to be signed by authorised parties and payments made to an Account can be verified by any one who has access to the network and the AccountId

c) Fabric smart contract can be used to record proprietary and private information related to the use case along with the agreement between parties on the amount to be paid for a particular transaction.

d)Stellar API for payment can be invoked off chain and the verification of this payment or any reconciliation required can be done as part of the fabric smart contract by using stellar APIs.

To understand this better, let’s consider the hyperledger fabric based smart contract for marbles, which can be easily deployed, on any fabric network, or on IBM Blockchain starter plan. Please go to the link above, to understand what this smart contract is about.

Here, if we want to build a workflow to transfer marbles, from buyer to seller ,based on an agreed upon price, for the transfer then these are the modifications which will be required in the smart contract and the client application to make the payment and verify the payment.

  1. Modify the owner struct to include the stellar account address of the person.
  2. Add a struct of type Offer to hold all the offers to buy marbles on sale and for seller to accept or reject the offer.
  3. Once the offer has been accepted and recorded on the fabric network, the buyer can initiate payment from the client side app, leveraging the Stellar APIs for making a payment. Payment API has fields for configuring the account address of sender, receiver, amount and memo. The memo field can be used to set the offerId against which the payment is being made.Relevant code can be found here.
  4. Once the buyer gets a transaction complete message from stellar, he can invoke a fabric smart contract method indicating the completion of transaction for a given offer.
  5. The fabric smart contract method can check the transaction details, using stellar APIs, and match the sender, receiver, amount and memo fields with corresponding values in offer before completing the transfer from seller to buyer as per the offer. Relevant code can be found here (file: write_ledger.go , method: payment_complete_against_offer) .

Sample code shows use of native currency (Lumens) but same APIs can be used for any other anchored assets as well. Although, we cannot achieve atomic swap yet, this approach is close to it, since once the offer has been accepted in Fabric network and payment has been done on Stellar, there is no going back, Fabric network smart contract will ensure the required transfer happens.

While the final code, with all the modifications(in smart contract and in client side — related to stellar only) , can be found here you can also go to the part 2, in this series, for detailed explanation of the steps and APIs used to achieve this.

Get Best Software Deals Directly In Your Inbox

--

--

Sachin Jha
Coinmonks

Cloud Solution Architect, Blockchain enthusiast and a passionate Badminton and Tennis player.