Javascript required
Skip to content Skip to sidebar Skip to footer

Ways to Upload Csv Into Hyperledger Composer

How to create an application on blockchain using Hyperledger

by Niharika Singh

How to create an application on blockchain using Hyperledger

PxeWV6Lrsvga2A-1V7ThzqsYCPqWq6zpxHda
Photograph by Sasha on Unsplash

Nosotros are going to build a digital bank using Hyperledger Composer. It volition have customers and accounts. At the end of it, y'all'll be able to transfer funds and record all transactions on blockchain. We'll expose a RESTful API for the same, so that even a person who has no inkling what blockchain is can make a beautiful user interface (UI) around it. We'll also create this awarding's UI in Angular.

I'grand super excited to share this step-by-pace guide with you. And then permit's get started correct away!

IMGn4dzREfDI32HrLkU-JSGA1b-NQVlOC3QG
Source: https://giphy.com/explore/excited

When I was first coding this out, I ran into errors. Lots and lots of them. But I call back that's expert, because it fabricated me larn a lot of things. Errors are essential. I got to a betoken where I felt switching information technology on and off would make things better. It almost made me lose my heed, simply information technology's an integral part in every hacker'due south life.

Before getting started, y'all need to ensure that the auto you lot're using is equipped with the required configurations. You may need to download sure prerequisites and fix up a basic dev environment. Below are the links to do that. Follow those steps before starting to develop an application, otherwise yous'll definitely run into stupid errors.

First install the Hyperledger composer. Then install the development surround.

There'south no need to start Playground while you're installing the surround.

Make certain docker is running, and when you run ./startFabric.sh it's going to take a couple of minutes. And so be patient.

At present that your car is all set, we tin start coding!

ISfnV6NFxgNcFao2U2fWY-gH3ND8qjxpp4lY
Source: http://www.forthebrokenhearted.net/170254395/4208888/posting/

Pace 1: Outline your Concern Network

Our Business Network Definition (BND) consists of the data model, transaction logic, and access control rules. The information model and admission control rules are coded in domain specific language (which is very elementary to catch up with). The transaction logic will be coded in JavaScript.

To create a BND, nosotros demand to create a suitable project construction on disk. We will create a skeleton business network using Yeoman. To create a project structure, open your terminal and run the following command:

                $ yo hyperledger-composer              

This will shoot out a series of questions as follows. You'll be required to apply your arrow keys to navigate through the answers.

CF0D-XmKKlo4bmAyumr3l91W90T1o1SIHTko

Open this project in your favorite text editor. I'one thousand using Visual Code. This is what the file structure volition expect like:

6xQNYHOyB8gCc0qNY7dJTjNEZToXeAdLQlsa

Delete the contents of test/logic.js. We won't exist using information technology at the moment.

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

Starting time, we'll define models/test.cto. It contains the course definitions for all assets, participants, and transactions in the business network. This file is written in Hyperledger Composer Modelling Linguistic communication.

                namespace examination              
                asset Account identified by accountId {o String accountId--> Customer ownero Double residue}              
                participant Client identified by customerId {o String customerIdo String firstNameo Cord lastName}              
                transaction AccountTransfer {--> Account from--> Account too Double amount}              

Account is an nugget which is uniquely identified with accountId. Each account is linked with Customer who is the owner of the business relationship. Account has a holding of remainder which indicates how much money the business relationship holds at any moment.

Customer is a participant which is uniquely identified with customerId. Each Customer has firstName and lastName.

AccountTransfer is a transaction that can occur to and from an Business relationship. And how much money is to be transferred is stored in corporeality.

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

In this file, we'll add together transaction logic in JavaScript.

                /*** Sample transaction* @param {exam.AccountTransfer} accountTransfer* @transaction*/              
                function accountTransfer(accountTransfer) {if (accountTransfer.from.balance < accountTransfer.to.balance) {throw new Fault ("Bereft 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('exam.Account');}).and then(function (assetRegistry) {return assetRegistry.update(accountTransfer.to);});              
                }              

@param {examination.AccountTransfer} accountTransfer is the decorator we put at the top of the file to link the transaction with our JavaScript function. Then nosotros validate if the account where funds are has plenty money. Otherwise, an error volition be thrown. And then we perform bones addition and subtraction on the business relationship'due south balance.

At this point, the most of import step is to update this on the blockchain. To do this we call getAssetRegistry API of our assets which is Business relationship. So nosotros update the retrieved assetRegistry for both the account doling out the funds and the business relationship receiving the funds.

Pace iii: Generate the Business Network Archive (BNA)

At present that the business network has been defined, it must exist packaged into a deployable business network archive (.bna) file.

Footstep 3.1: Navigate into the exam-bank app in your final.

Step 3.2: Run the following command:

                $ composer archive create -t dir -n .              

This creates a .bna file in the test-bank binder.

B3DUtkud4azEoCEoiIKV4PupBCxIPY4XOjLn

Step 4: Deploy the Business Network Archive file on the Fabric

Step 4.1: Install composer runtime

                $ composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName test-banking company              
HezXfxt3FVVtnHDfFkPVd6aghaKngGxrQBrF

Pace 4.2: Deploy the business organisation network

                $ composer network commencement --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile test-bank@0.0.1.bna --file networkadmin.carte              

(Brand sure yous're in the examination-depository financial institution folder).

LSkNP7nxN4tUcY3Dy01M22S6CivgkYLUJL4T

Pace 4.3: Import the network ambassador identity as a usable business network card

                $ composer card import --file networkadmin.carte              
keh-Fx-k7zKaN11RaG6LPsedpFTmpfyAF6cC

Footstep 4.4: To bank check that the business network has been deployed successfully, run the post-obit command to ping the network:

                $ composer network ping --menu admin@exam-bank              
VnU45AuKe6eCuQ82kr9AqTIJqNaeDMZJ-OKM

STEP 5: Expose a RESTful API

To create a RESTful API from your command line, run the post-obit command:

                $ composer-balance-server              

This will shoot a lot of questions.

0hTic2-uVL1dhxlNfTYlfo9lBdW3lbDr4HEJ

Now indicate your browser to http://localhost:3000/explorer.

Y'all'll see your beautiful blockchain API.

rUfk5ZJuROhQ5ipcqDPXAQ-5LLtIRxYQvyQk

Now permit'south add together ii Customers.

Fist, permit's add together a customer named Niharika Singh:

r9u1KOBTHhA1x5LOelLkurSaFwFaKYS0rVO0

We get a 200 response code.

Now nosotros'll add customer named Tvesha Singh in a similar mode.

To check if you've added them correctly, Get them.

v97WNZggvnZFaiYxpWW-pODw2v2D0g7qiWuJ

You'll see two customers in the response torso.

Now let'due south add 2 accounts linked to these two customers.

GeZJHVxzha7X3ao72H43wwSgQeSsbcxP2m8w

Add accounts this way. At present, GET them to bank check if y'all've added them correctly.

ByunFMXCKUkDkrZw6QuulazjTZgzRzEry3WD

Now permit's transfer 75 from Niharika to Tvesha.

F99wtlbUc8DVEvRgLOt8XWzMebf5wlbERYNo

Let'south bank check if the residuum is updated by getting the account information.

EWgbqrF7UtcVQfIRfOPatTdv40TgIYqVHyYg

Viola! It works. Niharika has 25 now, and Tvesha has 125.

Step vi: Angular Front end

To create Angular scaffolding automatically, run the following command in the examination-bank binder:

                $ yo              

This will ask multiple questions.

vyKb0G94DpcK4yExEBWdhTTJMb6Qav1g3hqW

And information technology volition take a couple of minutes.

Navigate into the bank-app.

                $ npm outset              

This starts the Angular server.

vCj4O1jxyOR3dEhonZekK-5l1PEVlcRmTMts

The Angular file structure is created every bit follows:

65mXKzp9zqtW-lXFUb3jC7ne9jV7QtIfwPQg

Signal your browser to http://localhost:4200. That'southward where the magic is happening! Yous'll see this screen:

hwqSianiBbujtAhMPwTirT0Le9Sb6wMJ9M1s

At present go to Assets in the top right corner and click on Account.

PuPBiymiOk9Bbyxx90z8WWUPHS9twirN3luf

These are the exact accounts we created.

So at present you can play around with this.

You accept your front finish and your backend ready!

All transactions that happen on localhost:3000 are reflected on localhost:4200 and vice versa. And this is all on blockchain.

8JLTo8tOyOiLLXdTsxO6KjAD7Vl7befHeWZo
Source: https://giphy.com/explore/thats-how-its-washed

Recently I wrote an article on blockchain'south use cases. I listed and explained about twenty ideas. They can exist found here:

How tin Republic of india get blockchained?
The blockchain epoch has simply begun and like any other technology, blockchain volition besides striking couple of roadblocks…medium.com

If you take a business idea and want to concretise it with applied science and architectural details, feel complimentary to reach me at niharika.3297@gmail.com

Learn to code for free. freeCodeCamp'southward open up source curriculum has helped more than 40,000 people get jobs as developers. Become started

braundcaliall76.blogspot.com

Source: https://www.freecodecamp.org/news/ultimate-end-to-end-tutorial-to-create-an-application-on-blockchain-using-hyperledger-3a83a80cbc71/