16

使用 Visual Studio Code 进行 Cadence 开发

 3 years ago
source link: https://www.chainnews.com/articles/993806103682.htm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用 Visual Studio Code 进行 Cadence 开发

使用 Visual Studio Code 进行 Cadence 开发

Cadence 编程语言简介

Cadence 编程语言是一种用于智能合约开发的新型高级编程语言。

该编程语言的重要特性如下:

  • 安全:它提供了强大的静态类型系统,按合约进行设计(前提条件和后置条件)和资源(受线性类型启发)。

  • 可审核:关注其可读性,使验证代码的工作变得容易,并使程序表达的意图明确,而花费的时间成本很小。

  • 简单:专注于开发人员的生产力和可用性,简化编写代码的过程,并提供良好的开发工具。

Cadence 开发

在 Flow 官网可以看到 Cadence 的在线 Playground ,开发者可以轻松学习开发 Cadence 在 Flow 的链上完成货币、收藏品和集市等智能合约的编写与测试。

Playground : https://play.onflow.org/

对于更复杂多样的功能,开发者需要在本地进行开发时,首先可以选择用 Visual Studio Code 开发 Cadence。那么,需要先安装 Visual Studio Code,并且要为它安装开发插件才能支持 Cadence 的开发,

Visual Studio Code Cadence 插件是与 Flow CLI 捆绑在一起,而 Flow CLI 是用于处理 Flow 指令的命令行工具。所以我们必须先要安装 flow-cli

•Windows 安装 flow-cli

    iex "& { $(irm 'https://storage.googleapis.com/flow-cli/install.ps1') }"

•Linux 或 macOS 安装 flow-cli

    sh -ci "$(curl -fsSL https://storage.googleapis.com/flow-cli/install.sh)"

Github:https://github.com/onflow/flow-cli

使用如下命令,查看一下 flow 版本,检测是否安装成功了。

    flow version

成功安装后,再来安装 CadenceVisual Studio Code 插件, 请在 macOS / Linux 上的终端或 Windows 上的 PowerShell 中运行以下命令:

    flow cadence install-vscode-extension

重新启动 Visual Studio Code 以完成插件的安装。

运行区块链模拟器

可以直接从 Visual Studio Code 运行模拟器。

请打开命令面板(在 macOS 和 Linux / Windows 上按),然后按 Shift+Command+PShift+Ctrl+P 后,输入 run emulator 启动本地区块链模拟器。

使用 Visual Studio Code 进行 Cadence 开发

这将打开一个新终端并启动 Flow 区块链的仿真版本。

另外,模拟器也可以在命令行上运行。

macOS / Linux 上的终端或 Windows 上的 PowerShell 中,运行:

    flow emulator start --init

模拟器运行后,您可以开始部署代码和提交事务。

•活跃账户

当模拟器在 VSCode 中运行时,活动帐户显示在编辑器的右下角。这表明要部署到哪个帐户合约,哪个帐户是提交交易的签名者。

•变更账户

要更改帐户,请单击屏幕右下角的活动帐户按钮。这将显示一个帐户列表供您选择。单击其中一个帐户,该帐户将被选为活动帐户。显示的第一个帐户是服务帐户,这是 Flow 的特殊帐户。不要将代码部署到该帐户,否则它将使模拟器混乱。切换到帐户 1 部署您的第一个合约。

使用 Visual Studio Code 进行 Cadence 开发

当模拟器运行时,您可以将合约部署到活动帐户。您应该在编辑器的合约定义上方看到一个按钮,显示。单击该按钮以部署合约。这将覆盖以前部署到该帐户的所有合约。

使用 Visual Studio Code 进行 Cadence 开发

    Deploy contract to account 0xf3fcd2c1a78f5eee

VScode 插件 Github:https://github.com/onflow/vscode-flow

使用 Visual Studio Code 进行 Cadence 开发

扫码添加小助手,进入 Cadence 语言学习社群


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK