import {
type AppKit,
type Base64String,
// Single-call transfer
transferTon,
// Two-step transfer: create a transaction object separately from sending it
createTransferTonTransaction,
sendTransaction,
} from '@ton/appkit';
async function sendToncoin(
/** Initialized AppKit instance */
kit: AppKit,
/** Recipient's TON wallet address as a string */
recipientAddress: string,
/** Amount in fractional Toncoin */
amount: string,
/** Optional comment string */
comment?: string,
/** Optional payload body as a BoC in Base64-encoded string */
payload?: Base64String,
/**
* Optional initial state (code and data) for deploying a new contract,
* stored as a BoC in Base64-encoded string
*/
stateInit?: Base64String,
) {
// Sign and send via TON Connect
const result = await transferTon(kit, {
recipientAddress,
amount,
// Optional comment OR payload, not both
...(comment && { comment }),
...(payload && { payload }),
...(stateInit && { stateInit }),
});
console.log('Transaction sent:', result.boc);
// Alternatively, build the transaction first with createTransferTonTransaction,
// then pass the resulting object to the sendTransaction function.
}