快速入門:使用 Visual Studio Code 連線至 Azure 區塊鏈服務聯盟網路Quickstart: Use Visual Studio Code to connect to an Azure Blockchain Service consortium network

在本快速入門中,您會安裝及使用適用於 Ethereum 的 Azure 區塊鏈開發套件 Visual Studio Code (VS Code) 擴充功能連結至 Azure 區塊鏈服務上的聯盟。In this quickstart, you install and use the Azure Blockchain Development Kit for Ethereum Visual Studio Code (VS Code) extension to attach to a consortium on Azure Blockchain Service. Azure 區塊鏈開發套件簡化了您在 Ethereum 區塊鏈總帳上建立、連線、建置及部署智慧型合約的方式。The Azure Blockchain Development Kit simplifies how you create, connect, build, and deploy smart contracts on Ethereum blockchain ledgers.

如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶If you don't have an Azure subscription, create a free account before you begin.

PrerequisitesPrerequisites

在 Windows 上,node-gyp 模組需要已安裝的 C++ 編譯器。On Windows, an installed C++ compiler is required for the node-gyp module. 您可以使用 MSBuild 工具:You can use the MSBuild tools:

  • 如果已安裝 Visual Studio 2017,請將 npm 設定為使用 MSBuild 工具搭配 npm config set msvs_version 2017 -g 命令If Visual Studio 2017 is installed, configure npm to use the MSBuild tools with the command npm config set msvs_version 2017 -g
  • 如果已安裝 Visual Studio 2019,請設定 npm 的 MSBuild 工具路徑。If Visual Studio 2019 is installed, set the MS build tools path for npm. 例如, npm config set msbuild_path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"For example, npm config set msbuild_path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"
  • 否則,請在提升權限的「以系統管理員身分執行」 命令殼層中,使用 npm install --global windows-build-tools 來安裝獨立的 VS Build 工具。Otherwise, install the stand-alone VS Build tools using npm install --global windows-build-tools in an elevated Run as administrator command shell.

如需 node-gyp 的詳細資訊,請參閱 GitHub 上的 node-gyp 存放庫For more information about node-gyp, see the node-gyp repository on GitHub.

確認 Azure 區塊鏈服務開發套件環境Verify Azure Blockchain Development Kit environment

Azure 區塊鏈服務開發套件會確認您是否已符合開發環境的必要條件。Azure Blockchain Development Kit verifies your development environment prerequisites have been met. 若要確認開發環境:To verify your development environment:

從 VS Code 命令選擇區選擇 [區塊鏈服務:顯示歡迎頁面]。From the VS Code command palette, choose Blockchain: Show Welcome Page.

Azure 區塊鏈服務開發套件會執行驗證指令碼,其大約需要一分鐘的時間才能完成。Azure Blockchain Development Kit runs a validation script that takes about a minute to complete. 您可以藉由選取 [終端機] > [新增終端機] 來檢視輸出。You can view the output by selecting Terminal > New Terminal. 在終端機的功能表列中,於下拉式清單內選取 [輸出] 索引標籤和 [Azure 區塊鏈服務] 。In the terminal menu bar, select the Output tab and Azure Blockchain in the dropdown. 驗證成功時會如下圖所示:Successful validation looks like the following image:

有效的開發環境

如果您缺少必要工具,名為 [Azure 區塊鏈服務開發套件 - 預覽] 的新索引標籤會列出必要工具與下載連結。If you are missing a required tool, a new tab named Azure Blockchain Development Kit - Preview lists the required tools with download links.

開發套件所需的應用程式

繼續進行本快速入門之前,請先安裝任何缺少的必要條件。Install any missing prerequisites before continuing with the quickstart.

連線至聯盟成員Connect to consortium member

您可以使用 Azure 區塊鏈服務開發套件 VS Code 擴充功能來連線至聯盟成員。You can connect to consortium members using the Azure Blockchain Development Kit VS Code extension. 在連線至聯盟後,您就可以對 Azure 區塊鏈服務聯盟成員編譯、建置和部署智慧型合約。Once connected to a consortium, you can compile, build, and deploy smart contracts to an Azure Blockchain Service consortium member.

如果您無法存取 Azure 區塊鏈服務聯盟成員,請完成必要的快速入門:使用 Azure 入口網站建立區塊鏈成員快速入門:使用 Azure CLI 建立 Azure 區塊鏈服務的區塊鏈成員If you don't have access to an Azure Blockchain Service consortium member, complete the prerequisite Quickstart: Create a blockchain member using the Azure portal or Quickstart: Create an Azure Blockchain Service blockchain member using Azure CLI.

  1. 在 VS Code 總管窗格中,展開 [Azure 區塊鏈服務] 擴充功能。In the VS Code explorer pane, expand the Azure Blockchain extension.

  2. 選取 [連線至網路] 。Select Connect to network.

    連線至網路

    如果系統提示您進行 Azure 驗證,請遵循提示以使用瀏覽器進行驗證。If prompted for Azure authentication, follow the prompts to authenticate using a browser.

  3. 選擇 [命令選擇區] 下拉式清單中的 [Azure 區塊鏈服務] 。Choose Azure Blockchain Service in the command palette dropdown.

  4. 選擇與 Azure 區塊鏈服務聯盟成員相關聯的訂用帳戶和資源群組。Choose the subscription and resource group associated with your Azure Blockchain Service consortium member.

  5. 從清單中選擇聯盟。Choose your consortium from the list.

VS Code 總管的提要欄位中會列出聯盟和區塊鏈成員。The consortium and blockchain members are listed in the VS Code explorer side bar.

總管中顯示的聯盟

後續步驟Next steps

在本快速入門中,您已使用適用於 Ethereum 的 Azure 區塊鏈開發套件 VS Code 擴充功能連結至 Azure 區塊鏈服務上的聯盟。In this quickstart, you used Azure Blockchain Development Kit for Ethereum VS Code extension to attach to a consortium on Azure Blockchain Service. 請嘗試進行下一個教學課程,使用適用於 Ethereum 的 Azure 區塊鏈開發套件,透過交易建立、建置、部署及執行智慧型合約函式。Try the next tutorial to use Azure Blockchain Development Kit for Ethereum to create, build, deploy, and execute a smart contract function via a transaction.