Tomo Docs
Tomo Docs
  • Overview
    • Introducing Tomo
    • Tomo's Key Management
  • Tomo SDK
    • TomoEVMKit
      • Quick Start
      • Use with Ethers.js
      • Migration from RainbowKit
      • Migration from Blocknative
      • Internal Wallet Services
      • Supported Chains
    • Tomo Web SDK
      • Quick Start
      • Solana Provider
      • EVM Provider
      • Bitcoin Provider
      • Tron Provider
      • Movement Provider
      • Sui Provider
      • Internal Wallet Services
    • Tomo Telegram SDK
      • Quick Start
      • Wallet Provider
        • EVM Provider
        • Solana Provider
        • Sui Provider (Beta)
        • TON Provider
      • Partners
    • Tomo Enterprise SDK
      • For Babylon
        • Install the SDK
        • Tomo Wallet Provider
        • Bitcoin Provider
        • Cosmos Provider
        • Multiple Connection Mode
        • Integrate Extension Wallet
          • Submit Wallet PR
          • Extend the SDK
          • Q & A
        • Integrate Mobile Wallet
  • TOMO WALLET
    • Tomo Wallets
    • Mobile Wallet
      • Tomo Keys
        • Bonding Curve Explained
        • How to: Tomo Keys
      • TomoID
        • How to: TomoID
        • How to: Connect Instagram
      • Tomo Socials
      • Tomo Android App
      • Tomo iOS App
    • Extension Wallet
      • Developer Manual
        • EVM Integration
        • Bitcoin Integration
      • Example of User Flows
        • Claiming Signet BTC
        • Staking at Testnet
      • Install Link
    • Telegram Wallet
      • Quick Start
      • Chains/Networks
      • User Manual
        • Account Security
        • Gift feature
        • FAQ
        • Transaction
        • Swap
  • ABOUT US
    • Brand Assets
    • Privacy Policy
Powered by GitBook
On this page
  • Connect with the Wallet​
  • Query Methods
  • Sending Methods
  • Payload for TON transaction
  • Payload for Jetton transaction
  1. Tomo SDK
  2. Tomo Telegram SDK
  3. Wallet Provider

TON Provider

The Tomo Telegram SDK provides a TON Provider for querying account data and sending transactions.

Connect with the Wallet​

Before using the provider, the user needs to log in to the wallet through the modal by following the method:

// connect wallet
await ton?.connectWallet();

We also support connecting through TON proof:

// the tonProof must be a hex string
const res = await tomo_ton.connect({
  tonProof: Buffer.from('your challenge', 'utf8').toString('hex'),
});

//At the dapp backend, check the tonProof res
const { tonProof } = res;

We also support connecting to the TON testnet as follows:

// You must use the Tomo TON provider to connect the testnet.
// Other wallet providers through TON Connect do not work.
const res = await tomo_ton.connect({
  network: 'testnet'
});

Query Methods

TON provider supports two query methods:

  • getAddress

  • getBalance

const address = ton.getAddress();

const balance = await ton.getBalance(address);

Sending Methods

In TON providers, we provide one send methods:

  • sendTransaction

This method allows signing and sending transactions in one call. The input for this method is TonTxParams, defined as the following:

export interface TonTxParams {
  valid_until?: number | bigint;
  validUntil?: number | bigint;
  network?: string;
  from?: string;
  messages: {
    address: string;
    amount: string; // nanoTon,  e.g. toNano('0.1').toString()
    stateInit?: string;
    payload?: string;
  }[];
}
// !amount must be nanoTon, 

You can construct your payload as a BOC(Bag of Cells) in the same way as the standard one. Then, convert it into a base64 string or hexadecimal string and pass it to sendTx method.

tomo_ton.sendTransaction(txParam: TonTxParams)

Payload for TON transaction

You can create a general payload using @ton/core

import { beginCell, toNano, Address } from '@ton/core';
const createPayloadByTonCoreCell = async (tokenAmount, recipientAddress: string) => {
    const destinationAddress = Address.parse(recipientAddress);

    const body = beginCell()
    .storeUint(0xf8a7ea5, 32) // Operation code for transferring
    .storeUint(0, 64) // / Query ID (can be any unique identifier)
    .storeCoins(tokenAmount) // Amount of tokens to send
    .storeAddress(destinationAddress) // destination
    .storeAddress(destinationAddress) // response_destination
    .storeBit(false) // null custom_payload
    .storeCoins(toNano('0.000001'))
    .storeBit(false) // false for empty forward payload
    .endCell();

    return body.toBoc().toString('base64');
};

Or tonweb:

import TonWeb from 'tonweb';
const createPayloadByTonWebCell = async (tokenAmount, recipientAddress) => {
    const tonWeb = new TonWeb(new TonWeb.HttpProvider());
    const cell = new tonWeb.boc.Cell();

    cell.bits.writeUint(0xf8a7ea5, 32); // Operation code for transferring tokens
    cell.bits.writeUint(0, 64); // Query ID (can be any unique identifier)
    cell.bits.writeCoins(tokenAmount); // Amount of tokens to send
    cell.bits.writeAddress(new TonWeb.utils.Address(recipientAddress)); // recipient address
    cell.bits.writeAddress(new TonWeb.utils.Address(recipientAddress)); // response address
    cell.bits.writeBit(false);  // null custom_payload
    cell.bits.writeCoins(TonWeb.utils.toNano('0.0001')); // forwardAmount
    cell.bits.writeBit(false); // empty forward payload

    return Buffer.from(await cell.toBoc()).toString('base64');
};

Payload for Jetton transaction

Below is an example use JettonWallet under tonweb for transferring jetton:

const createJettonTransferPayload = async (
    tokenAmount,
    recipientAddress,
  ) => {
    const tonWeb = new TonWeb(new TonWeb.HttpProvider());
    const jettonWallet = new TonWeb.token.jetton.JettonWallet(
        tonWeb.provider,
        {}
    );
    const transferBody = await jettonWallet.createTransferBody({
        queryId: 0,
        jettonAmount: tokenAmount,
        toAddress: new TonWeb.utils.Address(recipientAddress),
        forwardAmount: TonWeb.utils.toNano('0.0001'),
        responseAddress: new TonWeb.utils.Address(recipientAddress),
    });
    const uint8 = await transferBody.toBoc();
    return Buffer.from(uint8).toString('base64');
};
PreviousSui Provider (Beta)NextPartners

Last updated 6 months ago