0.1.0 • Published 6 years ago

hyperledger-fabric-example v0.1.0

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
6 years ago

Pre-requisites

Make sure following tools/runtimes are installed

Install

# Fetch the Hyperledger Farbic tools and docker images
curl -sSL https://goo.gl/iX9dek | bash
# Install typescript & ts-node (globally)
npm install -g ts-node typescript
# Install the dependencies of this project
npm install

Help

To see what are the commands that are available issue:

npm run info

Should see response similar to:

> hyperledger-fabric-example@0.1.0 info /Users/ksachdeva/Desktop/Dev/projects/myoss/hyperledger-fabric-example
> npm-scripts-info

info:
  List available script
start-orderer:
  Start the orderer container
stop-orderer:
  Stop the orderer container
start-containers:
  Starts all containers
stop-containers:
  Stops the containers
create-channel:
  Create the Channel
join-channel:
  Join Peers to the channel
install-chaincode:
  Install the chaincode on the peers
instantiate-chaincode:
  Instantiate the chaincode for the channel
invoke-transaction:
  Invoke a transaction
query-chaincode:
  Query the chaincode

Generating the crypto material for all the organizations

See Bootstrapping the Hyperledger Fabric Network (Part 1)

# You will find `cryptogen` in the `bin` folder created in the directory in which you
# executed `curl -sSL https://goo.gl/iX9dek | bash`
cryptogen generate --config=./crypto-config.yaml

Generating the Orderer genesis block

See Bootstrapping the Hyperledger Fabric Network (Part 2)

# You will find `configtxgen` in the `bin` folder created in the directory in which you
# executed `curl -sSL https://goo.gl/iX9dek | bash`
#
# Also make sure to set the FABRIC_CFG_PATH environment variable (it is required by configtxgen tool)
#
export FABRIC_CFG_PATH=$PWD
configtxgen -profile ThreeOrgsOrdererGenesis -outputBlock ./genesis.block

You can directly use the docker-compose command as specified in the blog post or using the command that I have hooked up in the package.json. The npm command also deletes 'production' folder so that every time your start the orderer node it starts with clean content.

npm run start-orderer

Similarly to stop the orderer containers simply issue

npm run stop-orderer

Generating the channel configuration transaction

See Bootstrapping the Hyperledger Fabric Network (Part 3)

configtxgen -profile ThreeOrgsChannel -outputCreateChannelTx ./ksachdeva-exp-channel-1.tx -channelID ksachdeva-exp-channel-1

Creating the new channel

See Bootstrapping the Hyperledger Fabric Network (Part 4)

npm run create-channel

Make Peers join the new channel

See Bootstrapping the Hyperledger Fabric Network (Part 5)

# Stop already running orderer containers
npm run stop-containers
# This will start both orderer & peer containers
npm run start-containers
# Create the channel again as when we start-containers we remove the previous data from the containers
npm run create-channel
# Join the channel
npm run join-channel

Install and instantiate the chaincode

See Bootstrapping the Hyperledger Fabric Network (Part 6)

npm run install-chaincode
npm run instantiate-chaincode

Invoke the transaction & Query the chaincode

See Invoking a transaction on Hyperledger Fabric Network

npm run query-chaincode
npm run invoke-transaction
npm run query-chaincode