Creating Application in Hyperledger

Step 1: Outline your Business Network

$ yo hyperledger-composer

Step 2.1: Coding out our Business Network (models/test.cto)


namespace test
asset Account identified by accountId {
o String accountId
--> Customer owner
o Double balance
}
participant Customer identified by customerId {
o String customerId
o String firstName
o String lastName
}
transaction AccountTransfer {
--> Account from
--> Account to
o Double amount
}

Step 2.2: Coding out the Business Network (lib/logic.js)

/**
* Sample transaction
* @param {test.AccountTransfer} accountTransfer
* @transaction
*/
function accountTransfer(accountTransfer) {
if (accountTransfer.from.balance < accountTransfer.to.balance) {
throw new Error ("Insufficient funds");
}
accountTransfer.from.balance -= accountTransfer.amount;
accountTransfer.to.balance += accountTransfer.amount;
return getAssetRegistry('test.Account')
.then (function (assetRegistry) {
return assetRegistry.update(accountTransfer.from);
})
.then (function () {
return getAssetRegistry('test.Account');
})
.then(function (assetRegistry) {
return assetRegistry.update(accountTransfer.to);
});
}

Step 3: Generate the Business Network Archive (BNA)

$ composer archive create -t dir -n . 
$ composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName test-bank
$ composer network start --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile test-bank@0.0.1.bna --file networkadmin.card
$ composer card import --file networkadmin.card
$ composer network ping --card admin@test-bank

STEP 5: Expose a RESTful API

$ composer-rest-server

Step 6: Angular Front End

$ yo

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Coding For Parents: Multiplication

The first week of Jadu

Single-dimensional & Multidimensional Arrays in Java.

Quarkus & Vertx, a powerfull combination — Part 2 Kafka Producer

WebGL needs a Home

Five Project Ideas for Intermediate JavaScript Developers

Starting Off on Analyzing AWS CUR

2183. Count Array Pairs Divisible by K ( Hard )

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ABHISHEK KUMAR

ABHISHEK KUMAR

More from Medium

Deploy Express JS App To AWS Lambda Using The Serverless Framework

Storage in Distributed Ledgers, Part 1

Enable Custom Domain to AWS API Gateway with Free SSL

Creating custom node from subflow in Node-RED