LogoLogo
ston-fi/docs
ston-fi/docs
  • User section
    • About
    • STON.fi Protocol
    • Fees
    • Glossary
    • Procedure for Adding Tokens to the Default List
    • Whitepaper
  • Developer section
    • Architecture
    • SDK
      • DEX v1 guide
        • reference
        • swap
        • provide liquidity
        • refund liquidity
        • burn liquidity tokens
      • DEX v2 guide
        • swap
        • provide liquidity
        • refund liquidity
        • burn liquidity tokens
        • withdraw fee from vault
      • Farm guide
        • stake in farm
        • claim farm rewards
        • unstake from farm
        • destroy farm NFT
      • Transaction sending guide
        • via ton
        • via tonweb
        • via tonconnect
      • v0.5 > v1.0.0 migration guide
      • v0.5 (deprecated)
        • DEX guide
          • swap
          • provide liquidity
          • refund liquidity
          • burn liquidity tokens
        • Farm guide
          • stake in farm
          • claim farm rewards
          • unstake from farm
          • destroy farm NFT
        • Transaction sending guide
          • via ton
          • via tonweb
          • via tonconnect
      • v0.4 > v0.5 migration guide
      • v0.4 (deprecated)
        • perform a swap operation
        • provide liquidity
        • refund liquidity
        • burn liquidity tokens
        • using get methods
        • create a custom router revision
    • API reference v1
      • Router
      • Pool
      • LpAccount
      • LpWallet
    • API reference v2
      • Router
      • Pool
      • LpAccount
      • LpWallet
      • Vault
      • Swap examples
      • LpProvide examples
      • Vault examples
      • Op Codes
    • DEX API
    • OMNISTON
      • Resolvers (How to become a resolver)
      • Swap overview
      • Swap extra
      • Swap grpc
      • React
      • Nodejs
      • Referral fees
    • Quickstart Guides
      • Swap Guide
      • Omniston Guide
  • Help
    • Contact Us
Powered by GitBook
On this page
Export as PDF
  1. Developer section
  2. SDK
  3. v0.5 (deprecated)
  4. Transaction sending guide

via tonweb

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

Previousvia tonNextvia tonconnect

Last updated 2 months ago

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

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();
README