Fabric Network with Fabcar Chaincode Example in between 3 Organizations
This a basic fabric network setup for 3 Organizations using Fabcar Chaincode for maintaining Car Informations.
Using Tool
- Up Network using
./scripts/networkUp.sh
- Down Network using
./scripts/networkDown.sh
Manual Setps :
Network Setup
cryptogen generate --config=./crypto-config.yaml
export FABRIC_CFG_PATH=$PWD
configtxgen -profile TwoOrdererOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
export CHANNEL_NAME=examplechannel
configtxgen -profile ExampleOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
/// update anchorexport CHANNEL_NAME=examplechannel
configtxgen -profile ExampleOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
configtxgen -profile ExampleOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
configtxgen -profile ExampleOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org3MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org3MSP
Up Network
export IMAGE_TAG="latest" export COMPOSE_PROJECT_NAME="mnproject"
docker-compose -f docker-compose-cli.yaml up -d
Down Network
docker-compose -f docker-compose-cli.yaml down
docker rm -f $(docker ps -aq)
//clear Containersdocker rmi -f $(docker images | grep "dev\|none\|test-vp\|peer[0-9]-" | awk '{print $3}')
//removeUnwantedImages
Remove Old Setup
rm -rvf ./channel-artifacts/* ./crypto-config
rm -rvf ./crypto-config
Create & Join Channel
docker exec -it cliorg1 bash
export CHANNEL_NAME=examplechannel
peer channel create -o orderer1.neo.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/neo.com/orderers/orderer1.neo.com/msp/tlscacerts/tlsca.neo.com-cert.pem
peer channel join -b examplechannel.block
Update the anchor peers
peer chaincode install -n examplecc -v 1.0 -p github.com/hyperledger/fabric/peer/chaincode/fabcar/go/
peer chaincode instantiate -o orderer1.neo.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/neo.com/orderers/orderer1.neo.com/msp/tlscacerts/tlsca.neo.com-cert.pem -C $CHANNEL_NAME -n examplecc -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer','Org2MSP.member','Org3MSP.member')"
query
1.peer chaincode query -C $CHANNEL_NAME -n examplecc -c '{"Args":["queryCar","CAR1"]}'
Invoke
peer chaincode invoke -o orderer1.neo.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/neo.com/orderers/orderer1.neo.com/msp/tlscacerts/tlsca.neo.com-cert.pem -C $CHANNEL_NAME -n examplecc -c '{"Args":["initLedger"]}'
NODE-SDK
Make Peers join the new channel
# 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
npm run install-chaincode
npm run instantiate-chaincode
npm run initLedger-chaincode
Invoke the transaction & Query the chaincode
npm run query-chaincode
npm run invoke-transaction
npm run query-chaincode