6.3 Access Instructions

6.3.2 Hyperledger Fabric Access Instruction

1. Use fabric-tools to interact with nodes

Example:

  • Start cli
 # docker-compose-cli.yaml file: 

 $ cat docker-compose-cli.yaml 

 version: '2'

 services:

 cli:

    container_name: fabric_peercli

    image: hyperledger/fabric-tools:2.2.0

    restart: always

    tty: true

    stdin_open: true

    environment:

    - FABRIC_LOGGING_SPEC=DEBUG

    - CORE_PEER_TLS_ENABLED=true  

    - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt

    - CORE_PEER_ADDRESS=peer1.org1.example.com:1051

    - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp

    - CORE_PEER_LOCALMSPID=Org1MSP

    - ORDERER_CA=/etc/hyperledger/fabric/orderer/tlsca/tlsca.orderer.example.com-cert.pem

    - ORDERER_ADDRESS=orderer1.orderer.example.com:7050

    working_dir: /etc/hyperledger/fabric

    command: /bin/bash

    volumes:

    - /var/run/:/host/var/run/

    - ./certs/ordererOrganizations/orderer.example.com:/etc/hyperledger/fabric/orderer

    - ./certs/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp:/etc/hyperledger/fabric/msp

    - ./certs/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls

        - ./sharedfiles/chaincode:/etc/hyperledger/fabric/src

        extra_hosts:

        - "orderer1.orderer.example.com:161.189.69.75"

        - "peer1.org1.example.com:161.189.69.75"
  • Access to containers for chaincode deployment and invocation
 #Chaincode deployment

 // package 

 peer lifecycle chaincode package basic414.tar.gz --path ./asset-transfer-basic/chaincode-javascript/ --lang node --label basic414

 // install 

 peer lifecycle chaincode install basic414.tar.gz

 // queryinstalled

 peer lifecycle chaincode queryinstalled

 // approveformyorg 

 peer lifecycle chaincode approveformyorg --name basic414 --package-id basic414:16bf72ced8451fc6fd94bd139de1532adfdd190af075c2e84a87513915a97365 -o $ORDERER_ADDRESS --tls --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE --cafile $ORDERER_CA --version 1.0 --channelID netchannel --sequence 1 --connTimeout 30s

 // queryapproved 

 peer lifecycle chaincode queryapproved --channelID netchannel -n basic414 

 // checkcommitreadiness

 peer lifecycle chaincode checkcommitreadiness --channelID netchannel --name basic414 --version 1.0 --sequence 1 --output json

 // commit 

 peer lifecycle chaincode commit -o $ORDERER_ADDRESS --cafile $ORDERER_CA --channelID netchannel --name basic414 --version 1.0 --sequence 1  --peerAddresses $CORE_PEER_ADDRESS --tls --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE 

 // querycommitted 

 peer lifecycle chaincode querycommitted -o $ORDERER_ADDRESS --channelID netchannel --tls --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE --cafile $ORDERER_CA

 #Invoke the chaincode

 // InitLedger

 peer chaincode invoke -o $ORDERER_ADDRESS --tls --cafile $ORDERER_CA   -C netchannel -n basic414 --peerAddresses $CORE_PEER_ADDRESS --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE -c '{"Args":["InitLedger"]}' 

 // GetAllAssets

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

 // CreateAsset

 peer chaincode invoke -o $ORDERER_ADDRESS --tls --cafile $ORDERER_CA   -C netchannel -n basic414 --peerAddresses $CORE_PEER_ADDRESS --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE -c '{"Args":["CreateAsset","asset7","white", "15", "zxl", "800"]}'

 //UpdateAsset

 peer chaincode invoke -o $ORDERER_ADDRESS --tls --cafile $ORDERER_CA   -C netchannel -n basic414 --peerAddresses $CORE_PEER_ADDRESS --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE -c '{"Args":["UpdateAsset","asset7","zxl", "1218", "zxl", "1218"]}'

 //ReadAsset

 peer chaincode query -C netchannel -n basic414 -c '{"Args":["ReadAsset","asset7"]}'
© 2019-2021 Red Date (Hong Kong) Technology Limited. all right reserved,powered by GitbookFile Modify: 2021-07-27 09:47:26

results matching ""

    No results matching ""

    results matching ""

      No results matching ""