ton-connect / sdk

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

[SDK]: Emulation error: no response; status code: undefined; #133

Closed matthewmaclay closed 10 months ago

matthewmaclay commented 10 months ago

Describe the bug

Successfully connected wallet via ton connect to TMA, but on confirm transaction see this screens in ton keeper and tg wallet telegram-cloud-photo-size-2-5302995931848890781-y telegram-cloud-photo-size-2-5303294333291717521-y

Expected behavior

Transcation will approve successfully.

Current behavior

Wallet see transaction, but i cant approve it

Steps to Reproduce

-

Environment

└─┬ @tonconnect/ui@2.0.0 └─┬ @tonconnect/sdk@3.0.0 ├── @tonconnect/isomorphic-eventsource@0.0.2 ├── @tonconnect/isomorphic-fetch@0.0.3 └── @tonconnect/protocol@2.2.6

Additional context

No response

matthewmaclay commented 10 months ago

Thanks @thekiba! This happened because I didn't form the payload correctly

      sendTransaction({
        messages: [
          {
            address: process.env.NEXT_PUBLIC_WALLET_ADDRESS as string,
            amount: toNanoTon(0.1),
            payload: btoa(`ID:${order.id}`), // error is here
          },
        ],
        validUntil: Math.floor(Date.now() / 1000) + 120, // 60 sec
      });

And right way is:

const transactionComment = (text: string) => {
  const cell = beginCell()
    .storeUint(0x00000000, 32)
    .storeStringTail(text)
    .endCell();

  const boc = cell.toBoc();
  return boc.toString("base64");
};
tonConnect.sendTransaction({
messages: [
    {
    address: process.env.NEXT_PUBLIC_WALLET_ADDRESS as string,
    amount: toNanoTon(order.amount),
    payload: transactionComment(`ID:${order.id}`),
    },
],
validUntil: Math.floor(Date.now() / 1000) + 120, // 60 sec
});