import { Address, beginCell, internal, toNano } from "@ton/core";
import { TonClient, WalletContractV4 } from "@ton/ton";
import { mnemonicToPrivateKey } from "@ton/crypto";
async function main() {
const jettonMasterAddress = Address.parse('<JETTON_MASTER_ADDR>');
const receiverAddress = Address.parse('<RECEIVER_ADDR>');
const destinationAddress = Address.parse('<WALLET_ADDR>');
// let's add some forward_payload
const forwardPayload = beginCell()
.storeUint(0, 32) // 0 opcode means we have a comment
.storeStringTail('Mint')
.endCell();
// Forming the master message
// internal transfer is also unspecified by the standard, but there is a suggested format in TEP 0074
const masterMessage = beginCell()
.storeUint(0x178d4519, 32) // opcode for jetton transfer-internal
.storeUint(0, 64) // query id
.storeCoins(toNano(5)) // jetton amount, amount * 10^9. That is an amount we want to mint
.storeAddress(jettonMasterAddress) // from_address. For minting could be any. The Jetton wallet will check from context that the sender is the Jetton master contract and accept the transfer.
.storeAddress(destinationAddress) // response destination
.storeCoins(toNano('0.02')) // forward_ton_amount - if >0, will send notification message
.storeBit(1) // either forward_payload
.storeRef(forwardPayload) // we have forward_payload, store it as a reference
.endCell();
// forming the mint message
const mintMessageBody = beginCell()
.storeUint(0x642b7d07, 32) // opcode for mint
.storeUint(0, 64) // query id
.storeAddress(receiverAddress) // the user's regular wallet address
.storeCoins(toNano(0.1)) // Toncoin intended to user's Jetton wallet
.storeRef(masterMessage) // internal transfer message
.endCell();
const mintMessage = internal({
to: jettonMasterAddress,
value: toNano('0.1'),
bounce: true,
body: mintMessageBody
});
// connect to your regular wallet
const client = new TonClient({
endpoint: 'https://toncenter.com/api/v2/jsonRPC',
});
const provider = client.provider(destinationAddress);
const MNEMONIC = process.env.MNEMONIC;
if (!MNEMONIC) throw new Error("Set MNEMONIC to a test mnemonic (testnet).");
const keyPair = await mnemonicToPrivateKey(MNEMONIC.split(" "));
const walletContract = WalletContractV4.create({
workchain: 0,
publicKey: keyPair.publicKey,
});
// send the mint message through your wallet
const seqno = await walletContract.getSeqno(provider);
await walletContract.sendTransfer(provider, {
seqno: seqno,
secretKey: keyPair.secretKey,
messages: [
mintMessage,
],
});
}
void main();