|
1 | 1 | ---
|
2 | 2 | sidebar_position: 1
|
3 | 3 | ---
|
| 4 | + |
4 | 5 | # 准备环境
|
| 6 | + |
| 7 | +## [sCrypt](https://scrypt.io/) |
| 8 | + |
| 9 | +MVC 智能合约开发使用 sCrypt 开发套件,sCrypt 开发语言分成两个大版本。 |
| 10 | + |
| 11 | +### [scrypt classic](https://scrypt-ide.readthedocs.io/en/latest/getting_started.html) |
| 12 | +使用scrypt classic编写智能合约,合约源文件以.scrypt结尾,使用 scryptc 编译为 [bvm 字节码](https://en.bitcoin.it/wiki/Script#Constants),scryptlib实例化合约、构造交易、测试合约、部署上链。目前官方已不建议使用。 |
| 13 | + |
| 14 | + |
| 15 | +### [scrypt](https://docs.scrypt.io/) |
| 16 | +使用 TypeScript 来编写智能合约,合约源文件以.ts结尾,具体流程为scrypt-ts-transpiler 转义 .ts 为.scrypt, scryptc 编译为 bvm 字节码,最后用scrypt-ts 实例化合约、构造交易、测试合约、部署上链。 |
| 17 | + |
| 18 | +- 对 bvm 运行时变量进行 log |
| 19 | +- 只需编写TypeScript,方便前后端集成 |
| 20 | +- 打包为npm package,方便复用合约,分发合约 |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +### mvc合约 |
| 25 | + |
| 26 | +mvc合约在设计开发之初scrypt还没完善,因此采用了scrypt classic,下面是几个合约的开发类型及项目地址。 |
| 27 | +| 合约 | 开发类型 | |
| 28 | +|---|---| |
| 29 | +| [token-core](https://github.com/mvc-labs/token-core) | scrypt classic | |
| 30 | +| [nft-core](https://github.com/mvc-labs/nft-core) | scrypt classic | |
| 31 | +| [mvcdao-core](https://github.com/mvc-labs/mvcdao-core) | scrypt classic | |
| 32 | +| [token-core-ts](https://github.com/xiangpengm/token-core-ts) | scrypt classic + scrypt | |
| 33 | + |
| 34 | +token-core-ts是对mvc原token、nft合约翻译为scrypt,但是测试用例沿用了scrypt classic,因此开发类型为两种混用。由于scrypt-ts库主要面向BSV不能直接在MVC链使用,因此使用 [patch-package](https://github.com/ds300/patch-package)的方式适配MVC,具体使用方式下文详述。 |
| 35 | + |
| 36 | + |
| 37 | +## 第一个MVC sCrypt合约工程 |
| 38 | + |
| 39 | +### [使用scrypt-cli创建项目](https://docs.scrypt.io/installation) |
| 40 | + |
| 41 | +```bash |
| 42 | +npx scrypt-cli project demo |
| 43 | +cd demo && npm i |
| 44 | +``` |
| 45 | + |
| 46 | + |
| 47 | +### 添加patch指令 |
| 48 | + |
| 49 | +添加patch指令进入package.json |
| 50 | + |
| 51 | +``` |
| 52 | +"patch": "sh -c \"$(curl -fsSL https://raw.githubusercontent.com/xiangpengm/token-core-ts/main/patches/patch_1.3.31.sh)\"" |
| 53 | +``` |
| 54 | + |
| 55 | + |
| 56 | +### 执行patch |
| 57 | + |
| 58 | +```bash |
| 59 | +npm run patch |
| 60 | +``` |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +### 执行scrypt-ts本地测试 |
| 65 | + |
| 66 | +``` |
| 67 | +npm run test |
| 68 | +``` |
| 69 | + |
0 commit comments