You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.5 KiB

2 years ago
import { beginCell, contractAddress, toNano, TonClient, TonClient4, Address, WalletContractV3R2, internal, fromNano, Cell} from "ton";
2 years ago
import {mnemonicToPrivateKey} from "ton-crypto";
2 years ago
import {buildOnchainMetadata} from "./utils/jetton-helpers";
import {SampleJetton} from "./output/jetton_SampleJetton";
2 years ago
2 years ago
2 years ago
(async () => { //need changes for jetton
//create client for testnet Toncenter API
const client = new TonClient({
endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC',
apiKey: 'bb38df0c2756c66e2ab49f064e2484ec444b01244d2bd49793bd5b58f61ae3d2'
})
//create client for testnet sandboxv4 API - alternative endpoint
const client4 = new TonClient4({
endpoint: "https://sandbox-v4.tonhubapi.com"
})
// Insert your test wallet's 24 words, make sure you have some test Toncoins on its balance. Every deployment spent 0.5 test toncoin.
2 years ago
let mnemonics = "basic security merge opera inject core melody polar become force cool glance history order warfare consider company slim twice balcony scare shoot winner rude";
2 years ago
// read more about wallet apps https://ton.org/docs/participate/wallets/apps#tonhub-test-environment
let keyPair = await mnemonicToPrivateKey(mnemonics.split(" "));
let secretKey = keyPair.secretKey;
//workchain = 1 - masterchain (expensive operation cost, validator's election contract works here)
//workchain = 0 - basechain (normal operation cost, user's contracts works here)
let workchain = 0; //we are working in basechain.
//Create deployment wallet contract
2 years ago
let wallet = WalletContractV3R2.create({ workchain, publicKey: keyPair.publicKey});
2 years ago
let contract = client.open(wallet);
// Get deployment wallet balance
let balance: bigint = await contract.getBalance();
2 years ago
// This is example data - Modify these params for your own jetton
// - Data is stored on-chain (except for the image data itself)
const jettonParams = {
2 years ago
name: "TactJet11",
2 years ago
description: "This is description of Test tact jetton",
image: "https://ipfs.io/ipfs/QmbPZjC1tuP6ickCCBtoTCQ9gc3RpkbKx7C1LMYQdcLwti" // Image url
2 years ago
};
2 years ago
2 years ago
// Owner should usually be the deploying wallet's address.
2 years ago
let owner = Address.parse('EQAuAiFGgkxoQvBWXjXQcLYb8BW4fO6UJkt6_uCONJ2y5VUk');
2 years ago
2 years ago
2 years ago
// Create content Cell
2 years ago
let content = buildOnchainMetadata(jettonParams);
2 years ago
2 years ago
// Compute init data for deployment
2 years ago
let init = await SampleJetton.init(owner, content);
2 years ago
let destination_address = contractAddress(workchain, init);
2 years ago
let deployAmount = toNano('0.5');
let supply = 500;
let amount = BigInt(supply * Math.pow(10, 9));
2 years ago
2 years ago
// send a message on new address contract to deploy it
let seqno: number = await contract.getSeqno();
//TL-B mint#01fb345b amount:int257 = Mint
let msg = beginCell().storeBuffer(Buffer.from("01fb345b", "hex")).storeInt(amount, 257).endCell();
2 years ago
console.log('🛠Preparing new outgoing massage from deployment wallet. Seqno = ', seqno);
console.log('Current deployment wallet balance = ', fromNano(balance).toString(), '💎TON');
console.log('Totally supply for deployed Token = ', supply, ', amount = ', amount.toString());
2 years ago
await contract.sendTransfer({
seqno,
secretKey,
messages: [internal({
value: deployAmount,
to: destination_address,
init: {
code : init.code,
data : init.data
},
body: msg
2 years ago
})]
});
console.log('======deployment message sent to ', destination_address, ' ======');
})();