하이퍼레저1.4 네트워크 시작 (2부)

체인코드 설치

CLI를 이용한 체인코드 설치 & 초기화

peer0.org1(기본값으로 설정됨)에 설치

peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/


peer2.org2에 설치

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=peer2.org2.example.com:11051
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer2.org2.example.com/tls/ca.crt
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/


체인코드 컨테이너 실행확인

체인코드 초기화

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=peer2.org2.example.com:11051
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer2.org2.example.com/tls/ca.crt
peer chaincode instantiate -o orderer.example.com:7050 --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 -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
  • -c 옵션 : 체인코드 초기값(JSON 형식)을 지정함
  • -P 옵션 : 승인정책 명시

체인코드 실행

쿼리

peer0.org1에서 실행

a의 값을 물어봄
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'

거래

a에서 b로 10만큼 이동시킴, 이 트랜잭션은 검증을 피어들(peer0.org1, peer2.org2)을 지정해 줌
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer2.org2.example.com:11051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'


값 확인

네트워크 중지

> 네트워크 중지

  1. byfn 스크립트 사용
./byfn.sh down
  1. 수동으로 중지
docker-compose -f docker-compose-cli.yaml down
docker rm $(docker ps -aq)

좋은 웹페이지 즐겨찾기