Before using the provider, the user needs to log in to the wallet through the modal by following the method:
// connect walletawaitton?.connectWallet();
We also support connecting through TON proof:
// the tonProof must be a hex stringconstres=awaittomo_ton.connect({ tonProof:Buffer.from('your challenge','utf8').toString('hex'),});//At dapp backend, check the tonProof resconst { tonProof } = res;
This method allows signing and sending transactions in one call. The input for this method is TonTxParams, defined as the following:
exportinterfaceTonTxParams { 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 transfer transaction
You can create a payload using @ton/core
import { beginCell, toNano, Address } from'@ton/core';constcreatePayloadByTonCoreCell=async (tokenAmount, recipientAddress:string) => {constdestinationAddress=Address.parse(recipientAddress);constbody=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();returnbody.toBoc().toString('base64');};
Or tonweb:
import TonWeb from'tonweb';constcreatePayloadByTonWebCell=async (tokenAmount, recipientAddress) => {consttonWeb=newTonWeb(newTonWeb.HttpProvider());constcell=newtonWeb.boc.Cell();cell.bits.writeUint(0xf8a7ea5,32); // Operation code for transferring tokenscell.bits.writeUint(0,64); // Query ID (can be any unique identifier)cell.bits.writeCoins(tokenAmount); // Amount of tokens to sendcell.bits.writeAddress(newTonWeb.utils.Address(recipientAddress)); // recipient addresscell.bits.writeAddress(newTonWeb.utils.Address(recipientAddress)); // response addresscell.bits.writeBit(false); // null custom_payloadcell.bits.writeCoins(TonWeb.utils.toNano('0.0001')); // forwardAmountcell.bits.writeBit(false); // empty forward payloadreturnBuffer.from(awaitcell.toBoc()).toString('base64');};
Payload for Jetton transaction
Use JettonWallet under tonweb for transferring jetton: