TON 智能合约基础环境搭建
代码样例来在 TON 官网教学网站章节 3.2 设置编译工作流(Setting up a compile worklow),视频链接官网 或者 B站 观看(可以的话给个关注求求了😘)。
基础环境
安装 node.js 16
以上。安装 yarn 或者 npm,淘宝仓库可能存在包不存在的问题,我使用全局代理方式规避无法下载依赖的问题。
有诸多方法配置淘宝的源,但是不保证所有的依赖都存在。配置文件在
C:\User\{user_name}\
的.yarnrc
和.npmrc
中,yarn 会读取 npm 的配置信息。
使用yarn config set "strict-ssl" false -g
来忽略SSL证书报错。
代码实现
-
创建项目文件夹,并初始化项目:
mkdir { project_name} code { project_name} yarn init #
-
下载
typescript
和ton-sdk
依赖(npm 下为npm install
):yarn add typescript ts-node @types/node @swc/core @ton-community/func-js ton-core ton-crypto --dev
可能教程比较早,我在运行的时候提示缺失
@ton-community/func-js
、ton-core
以及ton-crypto
。 -
对
tsconfig.json
配置 ts,其中比较重要的是"target":"es2020"
。"es2020"
表示 TypeScript 代码将被编译为符合 ECMAScript 2020 规范的 JavaScript 代码:{ "compileroptions": { "target":"es2020", "module": "'commonjs", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibcheck": true,