Hyperledger Fabric测试网络运行官方Java链码[简约版]

文章目录

      • 启动测试网络
      • 使用peer CLI测试链码
      • 调用链码

启动测试网络

cd fabric-samples/test-network

network.sh的脚本语法是:network.sh [flag]

Hyperledger Fabric测试网络运行官方Java链码[简约版]_第1张图片

./network.sh up
./network.sh createChannel

在java源码路径下

chmod +744 gradlew
vim gradlew
:set ff=unix
:wq
./gradlew run

回到test-network路径下

./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-java -ccl java

Hyperledger Fabric测试网络运行官方Java链码[简约版]_第2张图片

Hyperledger Fabric测试网络运行官方Java链码[简约版]_第3张图片

Hyperledger Fabric测试网络运行官方Java链码[简约版]_第4张图片

使用peer CLI测试链码

设置环境变量

export PATH=$PATH:${PWD}/../bin
export FABRIC_CFG_PATH=${PWD}/../config/

作为Org1操作peer CLI:

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051

调用链码

初始化账本

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}'

Hyperledger Fabric测试网络运行官方Java链码[简约版]_第5张图片

查询账本

peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'

Hyperledger Fabric测试网络运行官方Java链码[简约版]_第6张图片

修改账本

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"TransferAsset","Args":["asset6","Christopher"]}'

Hyperledger Fabric测试网络运行官方Java链码[简约版]_第7张图片

你可能感兴趣的:(fabric,网络,java,区块链)