設定 Fab3 代理主機

在 Ethereum/EVM 開發世界中,許多用戶端和公事包都使用 web3 程式庫在 Ethereum 網路中部署及管理智慧型合約。

web3 程式庫會呼叫 Ethereum JSON RPC API,此 API 必須透過 web3 提供者取得。

fab3 代理主機是 web3 提供者,可公開一組 Ethereum JSON RPC API,並協助使用 web3 式從屬端搭配 EVM 鏈碼。fab3 代理主機使用 Hyperledger Fabric Go SDK 來連線,並與 Oracle Blockchain Platform evmcc 鏈碼互動。

下列步驟會引導您設定環境以使用 web3 程式庫和 fab3 代理主機,在 Ethereum Virtual Machine (EVM) 鏈碼中部署智慧合約並與其互動。

  • 設定 fab3 代理主機之前,您必須依照所有步驟來設定 EVM 鏈碼。請參閱在 Oracle Blockchain Platform 上執行 Solidity Smart Contracts with EVM 。EVM 鏈碼和 fab3 套裝軟體包含連線設定檔,包括 network.yaml 檔案和物件。
  • 下列步驟僅適用於在 Hyperledger Fabric v2.x 上執行的 Oracle Blockchain Platform 執行處理。
  1. 在服務主控台的開發人員工具頁籤上,開啟應用程式開發窗格,然後按一下下載包含連線設定檔的 Fab3 組態。您必須是管理員使用者才能下載檔案。
  2. 從您下載的套裝軟體擷取檔案。
  3. 從服務主控台匯出管理證明資料。
    1. 網路頁籤上,按一下組織表格中您組織的其他動作按鈕。
    2. 按一下「匯出管理證明資料」。
    3. 按一下確定以儲存證明資料存檔檔案。
    4. 將下載的檔案解壓縮。
  4. 將您在上一個步驟中擷取的管理憑證 (.pem 檔案) 複製到下列位置,取代路徑中的實際組織和使用者 ID:
    ./artifacts/crypto/peerOrganizations/<organization-id>/users/<user-id>/msp/signcerts/
    ./artifacts/crypto/peerOrganizations/<organization-id>/users/<user-id>/msp/keystore/
  5. 設定 fab3 代理主機所需的環境變數。如需有關必要環境變數的詳細資訊,請參閱 EVM Smart ContractsSetting up the Fab Proxy
    export FAB3_CONFIG= # Path to the network.yaml in the extracted EVM chaincode and fab3 package
    export FAB3_USER= # User identity being used for the proxy (Matches the users names in the crypto-config directory specified in the config)
    export FAB3_ORG= # Organization of the specified user
    export FAB3_CHANNEL= # Channel to be used for the transactions
    export FAB3_CCID= # ID of the EVM Chaincode deployed in your fabric network
    export FAB3_PORT=5000 # Port the proxy will listen on. If not provided, the default is 5000.
  6. 在您解壓縮 fab3 套件的資料夾中開啟終端機視窗。在 Hyperledger EVM Smart Contracts 文件中,依照建立 Fab 代理主機一節中的步驟建立結構描述代理主機,並在連線至代理主機一節中,安裝 web3 並連線至代理主機。
您現在可以依照 Hyperledger EVM Smart Contracts 文件部署合約與部署的合約互動區段中的步驟,使用 web3 程式庫部署和與智慧合約互動。