在 TON 上编译和构建智能合约
以下是构建智能合约的库和库列表。
简而言之:
- 在大多数情况下,使用Blueprint SDK就足够了。
- 如果您需要更低级别的方法,可以使用ton-compiler或func-js。
Blueprint
概览
TON区块链的开发环境,用于编写、测试和部署智能合约。在Blueprint git库中了解更多信息。
安装
在终端运行以下命令以创建一个新项目,并按照屏幕上的指示操作:
npm create ton@latest
特点
- 构建、测试和部署智能合约的简化工作流程
- 使用您最喜欢的钱包(例如Tonkeeper)轻松部署到主网/测试网
- 在一个独立的区块链中快速测试多个智能合约,该区块链在进程中运行
技术栈
- 使用https://github.com/ton-community/func-js编译FunC(无CLI)
- 使用https://github.com/ton-community/sandbox测试智能合约
- 使用TON Connect 2、Tonhub wallet或
ton://
深链接部署智能合约
要求
- Node.js的最新版本,如v18,使用
node -v
验证版本 - 支持TypeScript和FunC的IDE,如Visual Studio Code,配备FunC插件
如何使用?
- 观看DoraHacks演示,了解使用blueprint的演示。
- 在Blueprint库中阅读详细的说明。
ton-compiler
概览
打包的FunC编译器,用于TON智能合约:
- GitHub:ton-community/ton-compiler
- NPM:ton-compiler
安装
- npm
- Yarn
- pnpm
npm install ton-compiler
yarn add ton-compiler
pnpm add ton-compiler
特点
- 多个FunC编译器版本
- 无需安装和编译TON
- 程序化和CLI接口
- 适用于cell测试
如何使用
这个包在项目中添加了ton-compiler
二进制文件。
FunC编译是一个多阶段过程。其中之一是将Func编译为Fift代码,然后将其编译为二进制表示。Fift编译器已经内置了Asm.fif。
FunC标准库已被捆绑,但可以在运行时禁用。
控制台使用
# Compile to binary form (for contract creation)
ton-compiler --input ./wallet.fc --output ./wallet.cell
# Compile to fift (useful for debugging)
ton-compiler --input ./wallet.fc --output-fift ./wallet.fif
# Compile to binary form and fift
ton-compiler --input ./wallet.fc --output ./wallet.cell --output-fift ./wallet.fif
# Disable stdlib
ton-compiler --no-stdlib --input ./wallet.fc --output ./wallet.cell --output-fift ./wallet.fif
# Pick version
ton-compiler --version "legacy" --input ./wallet.fc --output ./wallet.cell --output-fift ./wallet.fif