Hyperledger Fabric

簡介

Hyerledger下有幾個專案 https://www.hyperledger.org/community/projects

但其中只有 Fabric比較成熟

https://www.youtube.com/watch?v=js3Zjxbo8TM

hyperledger安裝使用Docker

官方文件先前非常不齊全,大多是IBM上較齊全,但最近官方的Docker安裝已經寫好,所以可以參考

http://hyperledger-fabric.readthedocs.io/en/latest/asset_setup.html

以下是前期需求

Go - 最新版
Docker - v1.13 or higher
Docker Compose - v1.8 or higher
Node.js & npm - node v6.9.5 and npm v3.10.10

之後啟動Docker後新增一個資料夾

mkdir -p my_dev_workspace/hackfest
cd my_dev_workspace/hackfest

之後下載環境

啟動六個Docker container (3 peers, a “solo” orderer, cli and CA)

試著輸入以下來查看是否有六個container

然後輸入以下使用cli這個container 並執行bash指令

進入bash後可輸入以下查看已經加入的節點

或是查看genesis block

然後離開

接著要下載相關 application source code 與 SDK modules

一樣在剛hackfest 的目錄底

然後輸入

目前為止我們就具有使用Fabric的基本環境

Asset Transfer with SDK

以下使用SDK進行設定 key value pairs of "a","100" & "b","200".

成功後如下圖

然後從A轉帳100給B

然後查看B的餘額

使用Cli

我們已經有了一個channel名稱為myc1接著我們可以新增一個myc2

再次輸入

新增myc2channel

之後會產生myc2.block 這個genesis block

接著把三個節點加入channel

接著以下這個指令,會使用mycc這個chaincode 並且 在channelmyc2peer0結點部署

之後轉帳

查詢B餘額

最後,如果你不想在一開始時就有預設channel,可把docker-compose-gettingstarted.yml的以下部分註解即可

之後要寫相關合約可參考以下教學文章

https://github.com/IBM-Blockchain/learn-chaincode

以下為舊資料

安裝環境

官方有提供三種方式 https://www.ibm.com/developerworks/cloud/library/cl-ibm-blockchain-101-quick-start-guide-for-developers-bluemix-trs/index.html#2-3

寫 chaincode

本地安裝

https://github.com/EasonWang01/learn-chaincode/blob/master/docs/setup.md

golang環境變數配置(gopath,goroot)

http://www.jianshu.com/p/4e699ff478a5

安裝好go後要設置gopath這個是我們工作路徑,之後

再來把https://github.com/EasonWang01/learn-chaincode

fork後clone入你的目錄下

之後可以build

記得0.5版不會有問題,0.6在build時會出現

與Blockchain互動

https://console.ng.bluemix.net/docs/services/blockchain/etn_sdk.html

https://github.com/IBM-Blockchain/learn-chaincode

先登入一個使用者

如果使用bluemix可在此查看預設的ID

如果是local部署可查看 https://github.com/hyperledger/fabric/blob/v0.6/membersrvc/membersrvc.yaml#L199

之後使用postman等工具像節點url發出request

部署chaincode

官方目前規定要部署必須將code先放在一個公開的repo上(ex:github)

使用bluemix(在以下網址申請帳號之後認證信箱然後再到此網址點選建立)

https://console.au-syd.bluemix.net/catalog/services/blockchain/

Last updated

Was this helpful?