# Hyperledger Fabric 筆記 * **Fabric document** https://hyperledger-fabric.readthedocs.io/en/release-2.2/whatis.html * **Fabric-samples** git checkout release-2.2 https://github.com/hyperledger/fabric-samples * **Fabric-ca document** https://hyperledger-fabric-ca.readthedocs.io/en/latest/ * **Chaincode javascripts SDK** https://hyperledger.github.io/fabric-chaincode-node/ * **Hyperledger-operations-console** https://github.com/hyperledger-labs/fabric-operations-console Introduction video https://www.youtube.com/watch?v=HGThtz5A6S8 ### Fabric-samples (啟動一個test-network和部署一個智能合約) 1. **安裝Prerequisites** https://hyperledger-fabric.readthedocs.io/en/release-2.2/prereqs.html 2. **啟動test-network** [可參考](https://hyperledger-fabric.readthedocs.io/en/release-2.2/test_network.html)(有些版本會不一樣) git clone https://github.com/hyperledger/fabric-samples.git cd fabric-samples git checkout release-2.2 curl -sSL https://bit.ly/2ysbOFE | bash -s 2.2.3 1.4.9 cd test-network 開啟test-network ./network.sh up createChannel -c mychannel -ca -i 2.2.3 -cai 1.4.9 3. **安裝智能合約** * 方法一 使用binary檔操作(建議先照這個做一次) 從Package the smart contract(javascript)開始 [參考](https://hyperledger-fabric.readthedocs.io/en/release-2.2/deploy_chaincode.html) * 方法二 使用script部署 ccn chaincode name ccp chaincode path ccl chaincode language ccep chaincode endorsement policy ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ -ccl javascript 4. **與智能合約互動** * 方法一 使用binary檔案操作 [參考](https://hyperledger-fabric.readthedocs.io/en/release-2.2/deploy_chaincode.html) * 方法二 使用SDK [參考](https://hyperledger-fabric.readthedocs.io/en/release-2.2/write_first_app.html)(Sample application開始看) ### Fabric-ca Public Key Infrastructure,包含Fabric-ca-client和Fabric-ca-server [參考](https://hyperledger-fabric-ca.readthedocs.io/en/latest/) User使用Fabric-ca-client向Fabric-ca-server申請x509證書(公鑰)和私鑰 在test-network中啟動ca是先用cryptogen產生自簽證書再啟動Fabric-ca-server ![](https://i.imgur.com/8LCqy6r.png) ![](https://i.imgur.com/31Zmu3M.png) tls-cert.pem 是https的那個s 拿來做加密 設定環境變數 export FABRIC_CA_CLIENT_HOME=${pwd} ![](https://i.imgur.com/nBQn2To.png) 使用Fabric-ca-client enroll會得到一個msp資料夾在FABRIC_CA_CLIENT_HOME路徑下,包含以下檔案 * cacerts/localhost-7054.pem的ca證書(沒設定domain name所以是localhost 和tls加密的那個一樣) * signcerts/cert.pem的使用者的證書 * keystore資料夾下的private key 可用 https://myssl.com/cert_decode.html 查看.pem證書 [可參考](https://github.com/hyperledger/fabric-samples/tree/main/fabcar)(從startFabric.sh可以看一下) ### 之後可以做... * trace network.sh * Fabric-samples中所有的Private data和State-Based Endorsement