您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

快速入门:使用 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.

先决条件Prerequisites

在 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 配置为通过命令 npm config set msvs_version 2017 -g 使用 MSBuild 工具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 命令面板中选择“Azure 区块链: 显示欢迎页”。From the VS Code command palette, choose Azure 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.