Deployment
Tact Deployer is a small library that integrates with TON Verifier that allows you to deploy your contracts safely using your favorite wallet without needing to manage keys or deploy contracts manually. Tact Deployer also automatically verifies your contract’s source code and you can be sure that your compiler is not compromised.
Requirements
Your contract MUST have the Deployer
trait from the @stdlib/deploy
package to be able to use Tact Deployer.
Installation
To add Tact Deployer to your project, just use yarn
:
yarn add @tact-lang/deployer
How to use
When you build your smart contracts using Tact, it produces a package (*.pkg) file that has all the required information about the built smart contract. To deploy your smart contract, you need to create a deployer instance, pass your package file to it and provide initial data for your contract.
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);
After following this link you will be able to deploy and verify your smart contract.