0% found this document useful (0 votes)
144 views

Practical 4 Asset Transfer App

The document describes steps to deploy an asset transfer application on a Hyperledger Fabric network. It involves setting up the network using Docker, creating a channel, deploying and invoking a secured asset transfer chaincode from both Org1 and Org2. Key steps include creating an asset as Org1, agreeing to sell the asset as Org2, and updating the asset description from both orgs. The process demonstrates cross-org interaction on a blockchain network using Hyperledger Fabric.

Uploaded by

pooja Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views

Practical 4 Asset Transfer App

The document describes steps to deploy an asset transfer application on a Hyperledger Fabric network. It involves setting up the network using Docker, creating a channel, deploying and invoking a secured asset transfer chaincode from both Org1 and Org2. Key steps include creating an asset as Org1, agreeing to sell the asset as Org2, and updating the asset description from both orgs. The process demonstrates cross-org interaction on a blockchain network using Hyperledger Fabric.

Uploaded by

pooja Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Subodh Kamble Roll no.

20 MSc Computer Science P2

Practical 4: Deploy an asset-transfer app using block chain. Learn app


development within a Hyperledger Fabric network.

Prerequisites:
1. Docker installed on your system
2. Hyperledger Fabric downloaded and installed
3. Familiarity with go lang <1.6/nodejs

$ cd fabric-samples/test-network

$ ./network.sh down
$ ./network.sh up createChannel -c mychannel
Subodh Kamble Roll no.20 MSc Computer Science P2

$ ./network.sh deployCC -ccn secured -ccp ../asset-transfer-secured-


agreement/chaincode-go/ -ccl go -ccep "OR('Org1MSP.peer','Org2MSP.peer')"

• Set the environment variables to operate as Org1 (posix compl shell)


$ export PATH=${PWD}/../bin:${PWD}:$PATH
$ export FABRIC_CFG_PATH=$PWD/../config/
$ export CORE_PEER_TLS_ENABLED=true
$ export CORE_PEER_LOCALMSPID="Org1MSP"
$ export
CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1
.example.com/users/[email protected]/msp
$ export
CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/o
rg1.example.com/peers/peer0.org1.example.com/tls/ca.crt
$ export CORE_PEER_ADDRESS=localhost:7051
Subodh Kamble Roll no.20 MSc Computer Science P2

• Set the environment variables to operate as Org2


$ export PATH=${PWD}/../bin:${PWD}:$PATH
$ export FABRIC_CFG_PATH=$PWD/../config/
$ export CORE_PEER_TLS_ENABLED=true
$ export CORE_PEER_LOCALMSPID="Org2MSP"
$ export
CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2
.example.com/users/[email protected]/msp
$ export
CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/o
rg2.example.com/peers/peer0.org2.example.com/tls/ca.crt
$ export CORE_PEER_ADDRESS=localhost:9051

• Create an asset

Operate from the Org1 terminal (top Terminal):

$ export ASSET_PROPERTIES=$(echo -n
"{\"object_type\":\"asset_properties\",\"color\":\"blue\",\"size\":35,\"salt\":\"
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\"}" | base64 | tr -d \\n)

$ export
ASSET_ID=d9923f21b770adbc79cbcc47a3aeecc81dc7f030bd129155301ce3932
be7fbcc
Success message:
{"object_type":"asset_properties","color":"blue","size":35,"salt":"a94a8fe5ccb
19ba61c4c0873d391e987982fbbd3"}
Subodh Kamble Roll no.20 MSc Computer Science P2

$ peer chaincode query -o localhost:7050 --ordererTLSHostnameOverride


orderer.example.com --tls --cafile
"${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.e
xample.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n
secured -c "{\"function\":\"ReadAsset\",\"Args\":[\"$ASSET_ID\"]}"
Success message:
{"objectType":"asset","assetID":"d9923f21b770adbc79cbcc47a3aeecc81dc7f0
30bd129155301ce3932be7fbcc","ownerOrg":"Org1MSP","publicDescription":"
A new asset for Org1MSP"}

$ peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride


orderer.example.com --tls --cafile
"${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.e
xample.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n
secured -c
"{\"function\":\"ChangePublicDescription\",\"Args\":[\"$ASSET_ID\",\"This
asset is for sale\"]}"
Success message:
2023-11-27 10:38:09.198 IST 0001 INFO [chaincodeCmd]
chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200

$ peer chaincode query -o localhost:7050 --ordererTLSHostnameOverride


orderer.example.com --tls --cafile
"${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.e
xample.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n
secured -c "{\"function\":\"ReadAsset\",\"Args\":[\"$ASSET_ID\"]}"
Success message:
Subodh Kamble Roll no.20 MSc Computer Science P2

{"objectType":"asset","assetID":"d9923f21b770adbc79cbcc47a3aeecc81dc7f0
30bd129155301ce3932be7fbcc","ownerOrg":"Org1MSP","publicDescription":"
This asset is for sale"}

Operate from the Org2 terminal (bottom Terminal):


$ export
ASSET_ID=d9923f21b770adbc79cbcc47a3aeecc81dc7f030bd129155301ce3932
be7fbcc
$ peer chaincode query -o localhost:7050 --ordererTLSHostnameOverride
orderer.example.com --tls --cafile
"${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.e
xample.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n
secured -c "{\"function\":\"ReadAsset\",\"Args\":[\"$ASSET_ID\"]}"
Success message:
{"objectType":"asset","assetID":"d9923f21b770adbc79cbcc47a3aeecc81dc7f0
30bd129155301ce3932be7fbcc","ownerOrg":"Org1MSP","publicDescription":"
This asset is for sale"}

$ peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride


orderer.example.com --tls --cafile
"${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.e
xample.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n
secured -c
"{\"function\":\"ChangePublicDescription\",\"Args\":[\"$ASSET_ID\",\"the
worst asset\"]}"
Success message:
2023-11-27 10:46:36.176 IST 0001 INFO [chaincodeCmd]
chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200
Subodh Kamble Roll no.20 MSc Computer Science P2

Agree to sell the asset


$ export ASSET_PRICE=$(echo -n
"{\"asset_id\":\"$ASSET_ID\",\"trade_id\":\"109f4b3c50d7b0df729d299bc6f8e
9ef9066971f\",\"price\":110}" | base64 | tr -d \\n)
$ peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride
orderer.example.com --tls --cafile
"${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.e
xample.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n
secured -c "{\"function\":\"AgreeToSell\",\"Args\":[\"$ASSET_ID\"]}" --transient
"{\"asset_price\":\"$ASSET_PRICE\"}"
Success message:
2023-11-27 10:51:32.734 IST 0001 INFO [chaincodeCmd]
chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200

$ peer chaincode query -o localhost:7050 --ordererTLSHostnameOverride


orderer.example.com --tls --cafile
"${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.e
xample.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n
secured -c "{\"function\":\"GetAssetSalesPrice\",\"Args\":[\"$ASSET_ID\"]}"
Success message:
{"asset_id":"d9923f21b770adbc79cbcc47a3aeecc81dc7f030bd129155301ce39
32be7fbcc","trade_id":"109f4b3c50d7b0df729d299bc6f8e9ef9066971f","price
":110}

Update the asset description as Org2


Subodh Kamble Roll no.20 MSc Computer Science P2

$ peer chaincode query -o localhost:7050 --ordererTLSHostnameOverride


orderer.example.com --tls --cafile
"${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.e
xample.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n
secured -c
"{\"function\":\"GetAssetPrivateProperties\",\"Args\":[\"$ASSET_ID\"]}"
Success message:
{"object_type":"asset_properties","color":"blue","size":35,"salt":"a94a8fe5ccb
19ba61c4c0873d391e987982fbbd3"}

$ peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride


orderer.example.com --tls --cafile
"${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.e
xample.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n
secured -c
"{\"function\":\"ChangePublicDescription\",\"Args\":[\"$ASSET_ID\",\"This
asset is not for sale\"]}"
Success message:
2023-11-27 11:18:30.055 IST 0001 INFO [chaincodeCmd]
chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200

$ peer chaincode query -o localhost:7050 --ordererTLSHostnameOverride


orderer.example.com --tls --cafile
"${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.e
xample.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n
secured -c "{\"function\":\"ReadAsset\",\"Args\":[\"$ASSET_ID\"]}"
Success message:
{"objectType":"asset","assetID":"d9923f21b770adbc79cbcc47a3aeecc81dc7f0
30bd129155301ce3932be7fbcc","ownerOrg":"Org1MSP","publicDescription":"
This asset is not for sale"}
Subodh Kamble Roll no.20 MSc Computer Science P2

Clean up (stopping chaincode):


$ ./network.sh down

Resource/credit: official Docs

You might also like