NetObjex Blog.

Hyperledger Composer Basics-Introduction To Hyperledger Composer

by Janice L. on December 3, 2018

  Hyperledger Composer is an application development framework which simplifies and expedites the creation of Hyperledger fabric blockchain applications. What we are going to develop is a payment system where a bank can issue asset / currency to a user. And user can transfer from his/her account to another account.
  1. Getting Started
  1. Open Chrome Browser (Download and Install chrome by visiting https://www.google.com/chrome/)
  2. Visit https://composer-playground.mybluemix.net/ to start developing blockchain application using Hyperledger Composer.
  1. Creating a Basic Network
We have to define a business network (nodes) and its policies to start with the development process.
  1. Click on Deploy a New Business Network
  2. Give the information as follows. Here we are defining the network parameters.
  • Business Network Name - payment-system
  • Description - Any random Description
  • Network Admin Card - Leave it blank
  • Model Network Starter Template - Select empty-business-network
  1. Connecting to Business Network
Now you can see a screen with your business network in it.  Click Connect Now to start the business network. You will get a screen as follows.
  1. Structure of Composer
The Hyperledger Composer mainly consists of 4 building blocs.
  1. CTO File - Here we define, Assets, Participants and various Transactions associated with the application.
  2. ACL File - It's an access control file where we define various access permissions and policies to operate on the network.
  3. JS File - It's a script file, used to operate various functionalities on the ledger.
  4. QRY File - Used to implement querying for ledger
  1. Development
First, we are going to do is defining Asset, Participants, and Transaction models in the model.cto file.
  1. Define the namespace as com.netobjex.payment
  2. Defining Currency as asset.
asset Currency identified by currencySymbol { o String currencyName o String currencySymbol o String currencyDescription o Integer liquidity }   Generic Structure for Asset Definition - Do not Use in code // String, Integer, Double, State, DateTime, Boolean asset AssetName identified by keyword { o dataType fieldName }
  1. Defining Participants model
participant User identified by userID { o String userID o String firstName o String lastName o Integer balance } Generic Structure for Participant Definition - Do not Use in code // String, Integer, Double, State, DateTime, Boolean participant ParticipantModel identified by keyword { o dataType fieldName }
  1. Defining Transaction
transaction Issue { --> Currency currency // Inheriting the model of Currency to currency --> User recipientUser // Inherting the model of User to recipientUser o Integer amount } Generic Structure for Transaction Definition - Do not Use in code // String, Integer, Double, State, DateTime, Boolean transaction TransactionName { o dataType fieldName }
  1. Click on Add a file to Include a script file. Name it as issue.js
  2. Here we are going to define the definition for Issue. (The transaction we defined above)
/** * Issue money from bank to a user * @param {com.netobjex.payment.Issue} issue - issue of money to user * @transaction */ async function issueMoney(issue) { issue.recipientUser.balance = issue.amount // Updating the Balance with Input Amount. let participantRegistry = await getParticipantRegistry('com.netobjex.payment.User'); // Retrieving Participant Registry await participantRegistry.update(issue.recipientUser); }
  1. Deploy changes and Click on Test.
  2. Create Participant  
  3. Create Asset
  4. Submit a Transaction
  1. Let's add more functionalities to it.
Currently the problem is, balance is overwriting rather than adding it into the existing balance. Let's modify the issueMoney function in issue.js file slightly to add more functionality. async function issueMoney(issue) { const currentBalance = issue.recipientUser.balance issue.recipientUser.balance = issue.amount + currentBalance let participantRegistry = await getParticipantRegistry('com.netobjex.payment.User'); await participantRegistry.update(issue.recipientUser); } Let's do a validation now, to check whether the issuer have enough fund before issuing the amount. async function issueMoney(issue) { const liquidity = issue.currency.liquidity const currentBalance = issue.recipientUser.balance if(liquidity >= issue.amount) { issue.recipientUser.balance = issue.amount + currentBalance issue.currency.liquidity = liquidity - issue.amount } else { alert("Insufficient fund in Bank") } let participantRegistry = await getParticipantRegistry('com.netobjex.payment.User'); let assetRegistry = await getAssetRegistry('com.netobjex.payment.Currency'); await participantRegistry.update(issue.recipientUser); await assetRegistry.update(issue.currency); }
  1. Defining Transaction between participants.
First, we have to define the transaction model. For that open model.cto and add following code.
  1. Model definition
transaction Transfer { --> User sender --> User receiver o Integer amount }
  1. Defining the transaction Now we have to define the transaction based on the model defined. Add a new script file. Name it as transfer.js
/** * Transfer of fund from one user to another * @param {com.netobjex.payment.Transfer} transfer - fund transfer between users * @transaction */ async function fundTransfer(transfer) { const senderBalance = transfer.sender.balance const receiverBalance = transfer.receiver.balance if(senderBalance >= transfer.amount) { transfer.receiver.balance = receiverBalance + transfer.amount transfer.sender.balance = senderBalance - transfer.amount } else { alert("Insufficient fund") } let participantRegistry = await getParticipantRegistry("com.netobjex.payment.User") await participantRegistry.update(transfer.receiver) await participantRegistry.update(transfer.sender) }   Deploy and Test like we do!  

Related Articles

Tags
# Accenture Open Innovation # advantages of digital processes # advantages of Industry 4.0 # advantages of interoperability # AI & Intelligent Automation # AI technologies # Analytics Quotient # applications of blockchain # Artificial Intelligence # Artificial Intelligence algorithms # Asset Management # asset tracking # Beacon # Beacon Registry # Beacon Technology # beacon zones # Benefits Of Digital Twin Technology # Big Data # Big Data analytics # Bitshares Blockchain # blockchain # blockchain applications # blockchain based electronic medical record systems # Blockchain company # blockchain event # Blockchain for Diamonds # blockchain for digital assets # Blockchain gateway # Blockchain gateway device # blockchain platform # Blockchain processes # Blockchain Services # blockchain setup # Blockchain strategies # blockchain system # blockchain technologies # blockchain technology # blockchain transactions # Bond # Browsa # Chain of Custody # client server computing # cloud computing # Cloud Dashboard # Commercial IoT Platform # Concept Behind Digital Twin Technology # concept of blockchain # concept of digital transformation # concept of Industry 4.0 # concept of IoT # crypto assets # Crypto NFC Tags # cryptocurrency # cryptocurrency market # cryptocurrency payments # cryptoeconomic funding # data acquisition # data colonization # data management # data marketplace # data marketplaces # data validation # deep learning artificial intelligence companies # developing blockchain application # Digital Assets # digital assets blockchain # digital banking # Digital Quotient # Digital transaction security # Digital Transformation # digital twin # Digital Twin platform # Digital twin technologies # Digital twin technology # Digital Wallet # Digital Wallet for Digital Assets # disruptive innovative technologies # distributed ledgers # electronic funds transfer # Electronic Health Records # enterprise gateway # enterprise systems and blockchain # Ethereum # first industrial revolution # fleet management # Fourth Industrial Revolution # Google Search # Healthcare # highlights of digital twin technology # how Blockchain can help in Logistics # Hyperledger Composer # Hyperledgers # hyperlocality # IIoT Integration # Immediate Payment Service # impact of Artificial intelligence # Industrial Internet # industrial internet of things # Industrie 4.0 # Industry 4.0 # Industry 4.0 model # Industry 4.0 technologies # information architectures # Intelligence Quotient # intelligent machines # internet banking transactions # internet of things # Internet of Things technology # Internet of Things trends # Interoperability platform # IoT # IoT AI Blockchain enterprise # IoT blockchain solutions # IoT capabilities # IoT CMS # IoT Gateway layers # IoT gateways # IoT infrastructure # IoT PaaS # IoT platform # IoT Platforms # IoT solutions # IoT systems # IoT Trends For 2019 # IoT use cases # IoT Use Cases For Smart Cities # IoToken # Iotoken cryptocurrency # leading artificial intelligence companies # Logistics ecosystem # Machine intelligence # machine learning # mainframe computing # manufacturing training # marketing campaign management # mobile app # mobile computing # Museums # NetObjex # NetObjex Blog # NetObjex crowdfunding campaign # NetObjex Digital Twin Platform # NetObjex Industry 4.0 # NetObjex Industry 4.0 solutions # netObjex Intelligent Connected Enterprises # NetObjex IoT devices # NetObjex IoT platform # NetObjex platform # NetObjex Smart Mobile Charging # Omni Channel # Open-Source # operations efficiency # payments system in India # PayPal # PayPal Beacon # permissioned blockchain # PiQube # popular IoT use cases # Privacy Policy # Registrar # remote computing # Request a Sandbox # Retail # Robotic Process Automation # Second Industrial Revolution # services of Industry 4.0 # Smart Charging Stations # smart cities # Smart City transportation # smart contracts # Smart Factory # Smart Legal Contracts # Smart Meters # Smart parking solutions # smart products # Software-as-a-service # staff efficiency # StartEngine Campaign # StartEngine crowdfunding campaign of NetObjex # technologies of Industry 4.0 # technology stack of IoT # Telrpay TFS # Theme Parks # Third Industrial Revolution # top IoT trends # Top IoT Trends For 2019 # trade finance # trade finance functions # trade finance process # trade finance transactions # transaction and data management # Unified Payments Interface # use AI for business growth # Visualization Tools # What Exactly Is Digital Twin Technology # Why Industry 4.0