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. Transaction sending guide

via ton

This section contains a guide for sending transactions in TON blockchain using @ton/ton

PreviousTransaction sending guideNextvia tonweb

Last updated 2 months ago

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

import { TonClient, WalletContractV4, internal, toNano } from "@ton/ton";
import { mnemonicToPrivateKey } from "@ton/crypto";
import { DEX, pTON } from "@ston-fi/sdk";

const client = new TonClient({
  endpoint: "https://toncenter.com/api/v2/jsonRPC",
});

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

const workchain = 0;
const wallet = WalletContractV4.create({
  workchain,
  publicKey: keyPair.publicKey,
});
const contract = client.open(wallet);

const dex = client.open(new DEX.v1.Router());

// swap 1 TON for a STON but not less than 0.1 STON
const txArgs = {
  offerAmount: toNano("1"),
  askJettonAddress: "EQA2kCVNwVsil2EM2mB0SkXytxCqQjS4mttjDpnXmwG9T6bO",
  minAskAmount: toNano("0.1"),
  proxyTon: new pTON.v1(),
  userWalletAddress: wallet.address.toString(),
};

// you can instantly send the transaction using the router method with send suffix
await dex.sendSwapTonToJetton(contract.sender(keyPair.secretKey), txArgs);

// or you can get the transaction parameters
const txParams = await dex.getSwapTonToJettonTxParams(txArgs);

// and send it manually later
await contract.sendTransfer({
  seqno: await contract.getSeqno(),
  secretKey: keyPair.secretKey,
  messages: [internal(txParams)],
});
README