ton-connect / sdk

SDK for TON Connect 2.0 — a comprehensive communication protocol between wallets and apps in TON ecosystem
Apache License 2.0
326 stars 92 forks source link

UI-REACT : Not able to burn jettons #273

Closed karanpokar closed 1 month ago

karanpokar commented 1 month ago

Describe the bug

I have created the telegram app to burn jettons. But some how it is failing on chain.

const prepareBurnTransaction = async (amountToBurn:string) => {
      const burnMessage = beginCell()
      .storeUint(0x595f07bc, 32) // 'burn' method selector
      .storeCoins(toNano(amountToBurn)) // Amount to burn in nanotons
      .endCell(); // Finalize the cell
      console.log(burnMessage,burnMessage.toBoc().toString('base64'));
      // Prepare the transaction object
      const transaction: SendTransactionRequest = {
        validUntil: Date.now() + 5 * 60 * 1000, // 5 minutes
        messages: [
          {
            address: selectedCoin?.address, // Jetton wallet address
            amount: toNano('0.05')?.toString(), // Transaction fee (e.g., 0.05 Toncoin for the burn)
            payload: burnMessage.toBoc().toString('base64'), // Burn method payload
          },
        ],
      };

      return transaction;
    };

    // Function to handle the burn transaction
    const handleBurn = async (successFunction:any) => {
      try {
        const transaction = await prepareBurnTransaction(amount?.toString()); // Prepare transaction
        console.log(transaction)
        const response:any=await tonConnectUI.sendTransaction(transaction) // Send transaction via TonConnect
        if (response.error) {
          setLoading(false);
          toast.error('Transaction Failed')
        } else {
        successFunction();

        }

      } catch (error) {

        console.error('Error burning Jettons:', error);
        alert('Failed to burn Jettons.');
      }
    };

Expected behavior

The app should be able to burn tokens onchain and should not fail.

Current behavior

Check this tx hash it fails on chain, https://tonscan.org/tx/cf156f99151014310e8a88b3908ed67fd09c1c26484d7753ee35e28d1355ff12

Screenshot 2024-10-19 at 11 17 45 AM

Steps to Reproduce

  1. Create a next app
  2. Add tonconnect ui
  3. Add the above code and try to burn the tokens

Environment

MacOS, Chrome

Additional context

No response