import { Address, beginCell, internal, toNano } from "@ton/core";
import { TonClient, WalletContractV4 } from "@ton/ton";
import { mnemonicToPrivateKey } from "@ton/crypto";
async function main() {
const jettonWalletAddress = Address
.parse('put your jetton wallet address');
const destinationAddress = Address
.parse('put destination wallet address');
const forwardPayload = beginCell()
.storeUint(0, 32) // 0 opcode means we have a comment
.storeStringTail('for coffee')
.endCell();
const messageBody = beginCell()
.storeUint(0x0f8a7ea5, 32) // opcode for jetton transfer
.storeUint(0, 64) // query id
.storeCoins(toNano(5)) // jetton amount, amount * 10^9
.storeAddress(destinationAddress) // the address of the new jetton owner
.storeAddress(destinationAddress) // response destination
.storeBit(0) // no custom payload
.storeCoins(toNano('0.02')) // forward amount - if >0, will send notification message
.storeBit(1) // store forwardPayload as a reference
.storeRef(forwardPayload)
.endCell();
const transferMessage = internal({
to: jettonWalletAddress,
value: toNano('0.1'),
bounce: true,
body: messageBody
});
// connect to your regular wallet
const client = new TonClient({
endpoint: 'https://toncenter.com/api/v2/jsonRPC',
});
const provider = client.provider(destinationAddress);
const your_mnemonic = 'put your mnemonic here, ...';
const keyPair = await mnemonicToPrivateKey(your_mnemonic.split(" "));
const walletContract = WalletContractV4.create({
workchain: 0,
publicKey: keyPair.publicKey,
});
// send the transfer message through your wallet
const seqno = await walletContract.getSeqno(provider);
await walletContract.sendTransfer(provider, {
seqno: seqno,
secretKey: keyPair.secretKey,
messages: [
transferMessage,
],
});
}