@laisky/tact-utils v0.0.1
tact-utils
A collection of TON Tact templates and tools.
Provides ready-to-use templates for Jetton, NFT, Traits, as well as some commonly used tools.
Click to view my article on using Tact to implement Jetton & NFTs! 🌟
Tested on Node.js v22.9
Still undergoing frequent updates!
Demo
https://s3.laisky.com/public/nft/connect/demo/index.html
Install
Install nodejs: https://github.com/nodesource/distributions
npm iBuild
npx blueprint buildExamples
helloworld is a simple example of a contract, while sample is an example that includes complex contract calls.
Please do not use helloworld and sample directly in your development.
Instead, use the code in common, jetton, and nft according to your needs.
Hello World
npx blueprint build helloworld
npx blueprint run --testnet --tonconnect helloworld
Jetton
To provide a more comprehensive code template, the sample deliberately includes a more complex Jetton implementation. You don't need to use the Sample directly in your project; rather, you should utilize the contracts and code in
jettonandcommonas per your requirements.
npx blueprint build sample
npx blueprint run --testnet --tonconnect jetton
? input the address of the jetton receiver(default to yourself):
0QARnduCSjymI91urfHE_jXlnTHrmr0e4yaPubtPQkgy553b
Sent transaction
-------------------------------------
jetton master address: EQD9PR60ImXHSE1KIemZGS30F0aHc0QUnfC6sMYyw9HtSGqA
Contract deployed at address EQD9PR60ImXHSE1KIemZGS30F0aHc0QUnfC6sMYyw9HtSGqA
You can view it at https://testnet.tonscan.org/address/EQD9PR60ImXHSE1KIemZGS30F0aHc0QUnfC6sMYyw9HtSGqA
mintable: true
owner: EQDRAI32YdVGZGDq18ygyPyflOpY5qIAA9ukd-OJ0CfYJ8SN
jetton content: https://s3.laisky.com/uploads/2024/09/jetton-sample.json
jetton total supply: 19000000000
-------------------------------------
jetton wallet address: EQDJiYKObYkxFFTR5v53TihdY723W8YCh34jvdu7qcwhBhVx
Contract deployed at address EQDJiYKObYkxFFTR5v53TihdY723W8YCh34jvdu7qcwhBhVx
You can view it at https://testnet.tonscan.org/address/EQDJiYKObYkxFFTR5v53TihdY723W8YCh34jvdu7qcwhBhVx
jetton wallet owner: EQARnduCSjymI91urfHE_jXlnTHrmr0e4yaPubtPQkgy53uU
jetton wallet master: EQD9PR60ImXHSE1KIemZGS30F0aHc0QUnfC6sMYyw9HtSGqA
jetton wallet balance: 19000000000
NFT
To provide a more comprehensive code template, the sample deliberately includes a more complex NFT implementation. You don't need to use the Sample directly in your project; rather, you should utilize the contracts and code in
nftandcommonas per your requirements.
npx blueprint build sample
npx blueprint run --testnet --tonconnect nft
Sent transaction
-------------------------------------
nft collection address: EQBHuZqwFHShebGvdOwRCeC1XbWPvYpOZsF7k7gkirDofyXG
Contract deployed at address EQBHuZqwFHShebGvdOwRCeC1XbWPvYpOZsF7k7gkirDofyXG
You can view it at https://testnet.tonscan.org/address/EQBHuZqwFHShebGvdOwRCeC1XbWPvYpOZsF7k7gkirDofyXG
nft collection owner: EQCVjlulLBzq9FSR2wQqZJU3uzE-TDXlvWKJAtHqu5SyHqoh
nft collection next index: 1
nft collection content: https://s3.laisky.com/uploads/2024/09/nft-sample-collection.json
-------------------------------------
nft item address: EQCub9bLM0sjI2qJGafmMFiPsDFJhq5RkDVQRlnNV9Rr_W77
Contract deployed at address EQCub9bLM0sjI2qJGafmMFiPsDFJhq5RkDVQRlnNV9Rr_W77
You can view it at https://testnet.tonscan.org/address/EQCub9bLM0sjI2qJGafmMFiPsDFJhq5RkDVQRlnNV9Rr_W77
nft item owner: EQCVjlulLBzq9FSR2wQqZJU3uzE-TDXlvWKJAtHqu5SyHqoh
nft item collection: EQBHuZqwFHShebGvdOwRCeC1XbWPvYpOZsF7k7gkirDofyXG
nft item index: 0
nft item content: https://s3.laisky.com/uploads/2024/09/nft-sample-item-0.json
Helpful Traits
Clone this repo to your project:
git clone https://github.com/Laisky/tact-utils.gitThen import the traits you need:
import './tact-utils/contracts/common/traits.tact';
import './tact-utils/contracts/common/messages.tact';Txable
Set a staticTaxFee to charge a fixed fee for every transaction, keeping it in the contract. Owners can adjust it anytime via SetStaticTaxFee msg.
contract YOUR_CONTRACT with Txable {
owner: Address;
staticTaxFee: Int as coins = ton("0.001");
}Upgradale
Allow the contract to be upgraded by the owner.
contract YOUR_CONTRACT with Upgradable {
owner: Address;
}Jetton
Jetton Template
Easily implement your own Jetton contract using Jetton Template.
import './tact-utils/contracts/jetton/jetton.tact';
import './tact-utils/contracts/common/messages.tact';
contract YOUR_CONTRACT {
owner: Address;
receive("SOME_MSG") {
let jettonMaster = initOf JettonMasterTemplate(
self.owner,
Tep64TokenData{
flag: 1,
content: "https://s3.laisky.com/uploads/2024/09/jetton-sample.json",
},
)
}
}Jetton Trait
You can also deeply customize Jetton contracts using Jetton Trait.
import './tact-utils/contracts/jetton/jetton.tact';
contract YOUR_CONTRACT with JettonMaster {
owner: Address;
staticTaxFee: Int as coins = ton("0.001");
lockedValue: Int as coins = 0;
content: Cell;
totalSupply: Int as coins;
mintable: Bool;
init(owner: Address, content: Tep64TokenData) {
self.owner = owner;
self.content = content.toCell();
self.totalSupply = 0;
self.mintable = true;
}
}Helpful Tools
Helpful Communites
1 year ago