3 deploy docker node
Write the docker-compose.yaml
file
Create a docker folder mkdir dacker
Create a docker-compose.yaml file in the docker folder vim docker-compose.yaml
(note the file structure)
version: '2' volumes: orderer.example.com: peer0.org1.example.com: peer1.org1.example.com: peer0.org2.example.com: peer1.org2.example.com: services: orderer.example.com: container_name: orderer.example.com image: hyperledger/fabric-orderer:2.2 environment: - FABRIC_LOGGING_SPEC=INFO - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_LISTENPORT=7050 -ORDERER_GENERAL_GENESISMETHOD=file - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block - ORDERER_GENERAL_LOCALMSPID=OrdererMSP - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp #- ORDERER_OPERATIONS_LISTENADDRESS=orderer.example.com:9443 # enabledTLS - ORDERER_GENERAL_TLS_ENABLED=true - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] - ORDERER_KAFKA_TOPIC_REPLICATIONFACTOR=1 - ORDERER_KAFKA_VERBOSE=true - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: orderer volumes: - ../channel-artifacts/orderer.genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls:/var/hyperledger/orderer/tls - orderer.example.com:/var/hyperledger/production/orderer ports: - 7050:7050 #-9443:9443 #networks: # - testwork peer0.org1.example.com: image: hyperledger/fabric-peer:2.2.10 container_name: peer0.org1.example.com environment: #- CORE_PEER_ADDRESSAUTODETECT=false - CORE_VM_ENDPOINT=unix///host/var/docker.sock - CORE_PEER_ID=peer0.org1.example.com - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 - CORE_PEER_LISTENADDRESS=0.0.0.0:7051 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052 - CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7061 - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051 - CORE_PEER_LOCALMSPID=Org1MSP - FABRIC_LOGGING_SPEC=INFO #- FABRIC_LOGGING_SPEC=INFO # info:core.chaincode=debug - CORE_PEER_TLS_ENABLED=true - CORE_PEER_GOSSIP_USELEADERELECTION=true - CORE_PEER_GOSSIP_ORGLEADER=false # whether this node is the org leader, default to false - CORE_PEER_PROFILE_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/var/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/var/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/var/hyperledger/fabric/tls/ca.crt - core_CHAINCODE_EXECUTETIMEOUT=300ms working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: peer node start volumes: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/var/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/var/hyperledger/fabric/tls - peer0.org1.example.com:/var/hyperledger/production ports: - 7051:7051 - 7052:7052 - 7053:7053 peer1.org1.example.com: image: hyperledger/fabric-peer:2.2.10 container_name: peer1.org1.example.com environment: #- CORE_PEER_ADDRESSAUTODETECT=false - CORE_VM_ENDPOINT=unix///host/var/docker.sock - CORE_PEER_ID=peer1.org1.example.com - CORE_PEER_ADDRESS=peer1.org1.example.com:7061 - CORE_PEER_LISTENADDRESS=0.0.0.0:7061 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7062 - CORE_PEER_CHAINCODEADDRESS=peer1.org1.example.com:7062 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:70561 - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:7051 - CORE_PEER_LOCALMSPID=Org1MSP - FABRIC_LOGGING_SPEC=INFO #- FABRIC_LOGGING_SPEC=INFO # info:core.chaincode=debug - CORE_PEER_TLS_ENABLED=true - CORE_PEER_GOSSIP_USELEADERELECTION=true - CORE_PEER_GOSSIP_ORGLEADER=false # whether this node is the org leader, default to false - CORE_PEER_PROFILE_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt - core_CHAINCODE_EXECUTETIMEOUT=300ms working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: peer node start volumes: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls - peer1.org1.example.com:/var/hyperledger/production ports: - 7061:7061 - 7062:7062 - 7063:7063 peer0.org2.example.com: image: hyperledger/fabric-peer:2.2.10 container_name: peer0.org2.example.com environment: #- CORE_PEER_ADDRESSAUTODETECT=false - CORE_VM_ENDPOINT=unix///host/var/docker.sock - CORE_PEER_ID=peer0.org2.example.com - CORE_PEER_ADDRESS=peer0.org2.example.com:8051 - CORE_PEER_LISTENADDRESS=0.0.0.0:8051 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052 - CORE_PEER_CHAINCODEADDRESS=peer0.org2.example.com:8052 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:8061 - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:8051 - CORE_PEER_LOCALMSPID=Org2MSP - FABRIC_LOGGING_SPEC=INFO #- FABRIC_LOGGING_SPEC=INFO # info:core.chaincode=debug - CORE_PEER_TLS_ENABLED=true - CORE_PEER_GOSSIP_USELEADERELECTION=true - CORE_PEER_GOSSIP_ORGLEADER=false # whether this node is the org leader, default to false - CORE_PEER_PROFILE_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt - core_CHAINCODE_EXECUTETIMEOUT=300ms working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: peer node start volumes: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls - peer0.org2.example.com:/var/hyperledger/production ports: - 8051:8051 -8052:8052 -8053:8053 peer1.org2.example.com: image: hyperledger/fabric-peer:2.2.10 container_name: peer1.org2.example.com environment: #- CORE_PEER_ADDRESSAUTODETECT=false - CORE_VM_ENDPOINT=unix///host/var/docker.sock - CORE_PEER_ID=peer1.org2.example.com - CORE_PEER_ADDRESS=peer1.org2.example.com:8061 - CORE_PEER_LISTENADDRESS=0.0.0.0:8061 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8062 - CORE_PEER_CHAINCODEADDRESS=peer1.org2.example.com:8062 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:8051 - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:8051 - CORE_PEER_LOCALMSPID=Org2MSP - FABRIC_LOGGING_SPEC=INFO #- FABRIC_LOGGING_SPEC=INFO # info:core.chaincode=debug - CORE_PEER_TLS_ENABLED=true - CORE_PEER_GOSSIP_USELEADERELECTION=true - CORE_PEER_GOSSIP_ORGLEADER=false # whether this node is the org leader, default to false - CORE_PEER_PROFILE_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt - core_CHAINCODE_EXECUTETIMEOUT=300ms working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: peer node start volumes: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp:/etc/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls - peer1.org2.example.com:/var/hyperledger/production ports: -8061:8061 -8062:8062 -8063:8063 cli1: image: hyperledger/fabric-tools:2.2.10 stdin_open: true container_name: cli tty: true depends_on: - peer0.org1.example.com - peer1.org1.example.com - peer0.org2.example.com - peer1.org2.example.com environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT=unix///host/var/docker.sock - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_ID=cli - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 # default to operate on peer0.org1 - CORE_PEER_LOCALMSPID=Org1MSP - CORE_PEER_TLS_ENABLED=true # to enable TLS, change to true - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp volumes: - /var/run/:/host/var/run/ - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/go - ../crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ - ../channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: /bin/bash cli2: image: hyperledger/fabric-tools:2.2.10 stdin_open: true container_name: cli2 tty: true depends_on: - peer0.org1.example.com - peer1.org1.example.com - peer0.org2.example.com - peer1.org2.example.com environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT=unix///host/var/docker.sock - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_ID=cli - CORE_PEER_ADDRESS=peer1.org1.example.com:7061 # default to operate on peer0.org1 - CORE_PEER_LOCALMSPID=Org1MSP - CORE_PEER_TLS_ENABLED=true # to enable TLS, change to true - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp volumes: - /var/run/:/host/var/run/ - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/go - ../crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ - ../channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: /bin/bash cli3: image: hyperledger/fabric-tools:2.2.10 stdin_open: true container_name: cli3 tty: true depends_on: - peer0.org1.example.com - peer1.org1.example.com - peer0.org2.example.com - peer1.org2.example.com environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT=unix///host/var/docker.sock - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_ID=cli - CORE_PEER_ADDRESS=peer0.org2.example.com:8051 # default to operate on peer0.org1 - CORE_PEER_LOCALMSPID=Org2MSP - CORE_PEER_TLS_ENABLED=true # to enable TLS, change to true - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp volumes: - /var/run/:/host/var/run/ - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/go - ../crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ - ../channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: /bin/bash cli14: image: hyperledger/fabric-tools:2.2.10 stdin_open: true container_name: cli4 tty: true depends_on: - peer0.org1.example.com - peer1.org1.example.com - peer0.org2.example.com - peer1.org2.example.com environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT=unix///host/var/docker.sock - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_ID=cli4 - CORE_PEER_ADDRESS=peer1.org2.example.com:8061 # default to operate on peer0.org1 - CORE_PEER_LOCALMSPID=Org2MSP - CORE_PEER_TLS_ENABLED=true # to enable TLS, change to true - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp volumes: - /var/run/:/host/var/run/ - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/go - ../crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ - ../channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: /bin/bash
4 Start the docker node. Different organizations start Peer nodes according to preset roles
docker-compose up -d
5 Creates a channel.
View usage of peer command
peer --help
Configure the local host file for domain name resolution, otherwise the nodes cannot communicate
gedit /etc/hosts
127.0.0.1 peer0.org1.example.com
127.0.0.1 peer1.org1.example.com
127.0.0.1 peer0.org2.example.com
127.0.0.1 peer1.org2.example.com
Enter the cli1 container
docker exec -it cli1 /bash/bin
Test network continuity
ping orderer.example.com
Generate channel file
peer channel create -o orderer.example.com:7050 -c mychannel -f "/tmp/channel-artifacts/$APP_CHANNEL.tx" --timeout "${TIMEOUT}s" --tls --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
After successful creation, a XXX.block
file will be generated in the current path.
Note: Handle bugs by looking at logs
View container information:
docker ps -a
View logs:docker logs -f container ID
6 Add the node to the channel.
Peer nodes use the initial block to join the created application channel
peer channel join -b mychannel.block
update anchor node
peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
Add the remaining nodes to the channel
Copy the generated channel file to the clients corresponding to all peers
docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block ./ docker cp mychannel.block cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer/ docker cp mychannel.block cli3:/opt/gopath/src/github.com/hyperledger/fabric/peer/ docker cp mychannel.block cli4:/opt/gopath/src/github.com/hyperledger/fabric/peer/
Enter the cli2 container: org1-peer1 join the channel:
docker exec -it cli2 /bash/bin
peer channel join -b mychannel.block
exit
Enter the cli3 container
docker exec -it cli2 /bash/bin
peer channel join -b mychannel.block
#Update the anchor node peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
exit
Enter the cli4 container
docker exec -it cli4 bash
peer channel join -b mychannel.block
exit
View block information on the channel
back to container 1
docker exec -it cli1 bash
View channel information
peer channel getinfo -c mychannel
View joined channels
peer channel list
7 Deployment and invocation of chaincode
Install chaincode
Copy the contract code to the chaincodes directory ~testwork/chaincode/go/ mounted on the host and docker cli container:
git clone https://XXXXX.git cp -r XXXXX xxxxx
Enter the cli container:
docker exec -it cli1 bash
Check whether the path has the chaincode file under the folder mapped by the container
Set proxy to pull dependency packages
In the chaincode/go directory, the newly added dependency package is automatically written to the vendor directory in the current project
cd /etc/hyperledger/fabric/chaincodes/go
go env -w GOPROXY=https://goproxy.cn,direct go mod vendor
Package chain code
peer lifecycle chaincode package smallbank.tar.gz --path /opt/gopath/pkg/src/github.com/hyperledger/..../chaincode/go/smallbank --label smallbank
Install chaincode on peer node
org1-peer0 node:
docker exec -it cli2 bash
peer lifecycle chaincode install xxx.tar.gz
Check the installation
peer lifecycle chaincode query installed
Install chaincode on other peer nodes
docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/sacc.tar.gz ./ docker cp sacc.tar.gz cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer/ docker cp sacc.tar.gz cli3:/opt/gopath/src/github.com/hyperledger/fabric/peer/ docker cp sacc.tar.gz cli4:/opt/gopath/src/github.com/hyperledger/fabric/peer/
cli2
docker exec -it cli2 bash
peer lifecycle chaincode install xxx.tar.gz
peer lifecycle chaincode queryinstalled #Check the installation status
exit
cli3
docker exec -it cli2 bash
peer lifecycle chaincode install xxx.tar.gz
peer lifecycle chaincode queryinstalled #Check the installation status
exit
cli4
docker exec -it cli4 bash
peer lifecycle chaincode install xxx.tar.gz
peer lifecycle chaincode queryinstalled #Check the installation status
exit
Approve chaincode definition
Members in the channel need to vote on the parameters of the chain code to decide whether to pass the chain code. Each member in a channel who wants to use the chain code needs to approve the chain code definition for his organization. Then, in the first step, he submits the approval to the ordering node. In the second step, it is distributed to all peer nodes. This approval is submitted by the organization administrator, just submit an approval transaction.
org1 approves the chaincode definition: .
docker exec -it cli1 bash
peer lifecycle chaincode approveformyorg -o orderer0.example.com:7050 --ordererTLSHostnameOverride orderer0.example.com --channelID businesschannel --name hyperledger-fabric-contract-java-demo --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls true --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
View chaincode approval status:
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name --version --init-required --sequence 1 -- tls --cafile --output json
exit
org2 approved chaincode definition:
docker exec -it cli3 bash
peer lifecycle chaincode approveformyorg -o orderer0.example.com:7050 --ordererTLSHostnameOverride orderer0.example.com --channelID businesschannel --name hyperledger-fabric-contract-java-demo --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 -- tls --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
Check that channel members have approved the same chaincode definition:
peer lifecycle chaincode checkcommitreadiness --channelID businesschannel --name hyperledger-fabric-contract-java-demo --version 1.0 --sequence 1 --tls --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com /msp/tlscacerts/tlsca.example.com-cert.pem --output json
The output is as follows:
{<!-- --> "approvals": {<!-- --> "Org1MSP": true, "Org2MSP": true } }
Submit the chaincode to the channel:
peer lifecycle chaincode commit - o orderer0.example.com:7050 --ordererTLSHostnameOverride orderer0.example.com --channelID businesschannel --name hyperledger-fabric-contract-java-demo --version 1.0 --sequence 1 --tls --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /etc/hyperledger/fabric/crypto-config /peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
Use the peer lifecycle chaincode querycommitted command to confirm that the chaincode definition has been committed to the channel:
peer lifecycle chaincode querycommitted --channelID businesschannel --name hyperledger-fabric-contract-java-demo --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.examp le.com-cert.pem
Call chaincode
chaincode instantiation
In fact, chaincode instantiation is a special transaction. After the chaincode is instantiated on a certain node, the instantiation information is broadcast to all nodes in the channel. If other nodes are instantiated again, there will naturally be conflicts.
# Call the createCat function to initialize the chaincode #According to the initial function in the chain code, pass in the corresponding parameters to initialize and instantiate peer chaincode invoke -o orderer0.example.com:7050 --ordererTLSHostnameOverride orderer0.example.com --tls --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C businesschannel -n hyperledger-fabric-contract-java-demo --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /etc/hyperledger/fabric/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{<!-- -->"function":"createCat","Args":["cat-0" , "tom" , "3" , "blue" , "big lazy cat"]}' # call the queryCat function peer chaincode query -C businesschannel -n hyperledger-fabric-contract-java-demo -c '{<!-- -->"Args":["queryCat" , "cat-0"]}'