設定 Fab3 代理主機

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

web3 程式庫會呼叫 Ethereum JSON RPC API,而 Ethereum JSON RPC 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 上使用 EVM 執行 Solidity Smart Contracts 。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 Contracts 中的 Setting 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 Proxy 小節中的步驟來建置 Fab Proxy,以及在連線至 Proxy 小節中安裝 web3 並連線至 Proxy。
您現在可以遵循 Hyperledger EVM Smart Contracts 文件部署合約與部署的合約互動區段中的步驟,使用 web3 程式庫部署與與互動智能合約。