部署
Tact Deployer 是一个与 TON Verifier 集成的小型库,可让您使用自己喜欢的钱包安全地部署合约,而无需管理密钥或手动部署合约。 Tact Deployer 还能自动验证合约的源代码,确保编译器不受损害。
要求
要使用 Tact Deployer,您的合约必须具有 @stdlib/deploy
包中的 Deployer
特性。
安装
要在项目中添加 Tact 部署器,只需使用 yarn
:
yarn add @tact-lang/deployer
如何使用
当你使用 Tact 构建智能合约时,它会生成一个包(*.pkg)文件,其中包含所构建智能合约的所有必要信息。 要在TON中部署智能合约,您需要发送附有init
数据的消息。
import * as fs from 'fs';import * as path from 'path';import { Address, contractAddress } from "ton";import { SampleTactContract } from "./output/sample_SampleTactContract";import { prepareTactDeployment } from "@tact-lang/deployer";
// Parameterslet testnet = true; // Flag for testnet or mainnetlet packageName = 'sample_SampleTactContract.pkg'; // Name of your package to deploylet outputPath = path.resolve(__dirname, 'output'); // Path to output directorylet owner = Address.parse('<put_address_here>'); // Our sample contract has an ownerlet init = await SampleTactContract.init(owner); // Create initial data for our contract
// Calculationslet address = contractAddress(0, init); // Calculate contract address. MUST match with the address in the verifierlet data = init.data.toBoc(); // Create init datalet pkg = fs.readFileSync( // Read package file path.resolve(outputPath, packageName));
// Prepare deploylet link = await prepareTactDeployment({ pkg, data, testnet });
// Present a deployment link and contract addressconsole.log('Address: ' + address.toString({ testOnly: testnet }));console.log('Deploy link: ' + link);
点击此链接后,您就可以部署和验证您的智能合约。