- Install Dockers
- Install VSCode, and VSCode Hyperledger Composer Plugin
- Install required npm node packages
> npm install -g composer-cli
> npm install -g generator-hyperledger-composer
> npm install -g composer-rest-server
> npm install -g yo
- Setting and running Hyperledger Fabric
> mkdir fabric-tools
> cd fabric-tools
> curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip
> unzip fabric-dev-servers.zip
> ./downloadFabric.sh
> ./startFabric.sh
> ./createPeerAdminCard.sh
- Create a new project directory
> mkdir app
> cd app
- Instantiate a Business network by yo npm plugin
> yo hyperledger-composer:businessnetwork
> Business network name: voting
> Description: A simple blockchain network
> Author name: saif
> Author email: s4saif.121@email.com
> License: Apache-2.0
> Namespace: org.acme.voting
- Navigate to business network folder and install the dependencies
> cd voting
> npm install
.cto file code
/**
* Write your model definitions here
*/
namespace org.acme.voting
participant voter identified by voterID {
o String voterID
o String fullName
}
asset ifVoted identified by voterID {
o String voterID
o Boolean votedOrNot
}
asset candidateVote identified by politicalParty {
o String politicalParty
o Integer totalVote
}
transaction vote {
--> candidateVote candidateVoteAsset
--> ifVoted ifVotedAsset
}
logic.js code
'use strict';
/**
* Write your transction processor functions here
*/
/**
* Sample transaction
* @param {org.acme.voting.vote} vote
* @transaction
*/
function vote(tx) {
if (!tx.ifVotedAsset.votedOrNot) {
tx.candidateVoteAsset.totalVote = tx.candidateVoteAsset.totalVote + 1;
return getAssetRegistry('org.acme.voting.candidateVote')
.then(function (assetRegistry) {
return assetRegistry.update(tx.candidateVoteAsset);
})
.then(function () {
return getAssetRegistry('org.acme.voting.ifVoted')
.then(function (assetRegistry) {
tx.ifVotedAsset.votedOrNot = true;
return assetRegistry.update(tx.ifVotedAsset);
})
});
}
}
- Creating the .bna file
> mkdir dir
> composer archive create --sourceType dir --sourceName . -a ./dist/network.bna
- Deploying the .bna file on the Hyperledger Fabric Blockchain
> composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName voting
> composer network start --card PeerAdmin@hlfv1 -A admin -S adminpw -a network.bna -f networkadmin.card
> composer card import -f networkadmin.card
- Interfacing you blockchain with Restfull CRUD Apis
> composer-rest-server