This section contains a guide for sending transactions in TON blockchain using @ton/ton
Ton package uses the sendTransfer method to send a transaction to the blockchain. An example of the usage is on their README.
import { TonClient, WalletContractV4, internal, toNano } from"@ton/ton";import { mnemonicToPrivateKey } from"@ton/crypto";import { DEX, pTON } from"@ston-fi/sdk";constclient=newTonClient({ endpoint:"https://toncenter.com/api/v2/jsonRPC",});constmnemonics=Array.from( { length:24 }, (_, i) =>`your mnemonic word ${i +1}`); // replace with your mnemonicconstkeyPair=awaitmnemonicToPrivateKey(mnemonics);constworkchain=0;constwallet=WalletContractV4.create({ workchain, publicKey:keyPair.publicKey,});constcontract=client.open(wallet);constdex=client.open(newDEX.v1.Router());// swap 1 TON for a STON but not less than 0.1 STONconsttxArgs= { offerAmount:toNano("1"), askJettonAddress:"EQA2kCVNwVsil2EM2mB0SkXytxCqQjS4mttjDpnXmwG9T6bO", minAskAmount:toNano("0.1"), proxyTon:newpTON.v1(), userWalletAddress:wallet.address.toString(),};// you can instantly send the transaction using the router method with send suffixawaitdex.sendSwapTonToJetton(contract.sender(keyPair.secretKey), txArgs);// or you can get the transaction parametersconsttxParams=awaitdex.getSwapTonToJettonTxParams(txArgs);// and send it manually laterawaitcontract.sendTransfer({ seqno:awaitcontract.getSeqno(), secretKey:keyPair.secretKey, messages: [internal(txParams)],});