via tonweb

This section contains a guide for sending transactions in TON blockchain using tonweb

Tonweb package uses the transfer method to send a transaction to the blockchain. An example of the usage is on their README.

import TonWeb from "tonweb";
import TonWebMnemonic from "tonweb-mnemonic";
import { DEX, pTON } from "@ston-fi/sdk";

const MNEMONIC = Array.from({ length: 24 }, (_, i) => `your mnemonic word ${i + 1}`); // replace with your mnemonic

const tonWeb = new TonWeb();

const client = new TonWeb.HttpProvider();

const keyPair = await TonWebMnemonic.mnemonicToKeyPair(MNEMONIC);

const wallet = new tonWeb.wallet.all.v4R2(client, {
    publicKey: keyPair.publicKey,
});

const dex = new DEX.v1.Router({
    tonApiClient: client,
})

const swapTxParams = await dex.buildSwapTonToJettonTxParams({
    offerAmount: TonWeb.utils.toNano('1'), // swap 1 TON
    askJettonAddress: 'EQA2kCVNwVsil2EM2mB0SkXytxCqQjS4mttjDpnXmwG9T6bO', // for a STON
    minAskAmount: TonWeb.utils.toNano('0.1'), // but not less than 0.1 STON
    proxyTonAddress: pTON.v1.address.toString(),
    userWalletAddress: (await wallet.getAddress()).toString(),
});

await wallet.methods.transfer({
    secretKey: keyPair.secretKey,
    toAddress: swapTxParams.to,
    amount: swapTxParams.gasAmount,
    seqno: await wallet.methods.seqno().call() ?? 0,
    payload: swapTxParams.payload,
    sendMode: 3,
}).send();

Last updated