Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[<SDK>]: how can I get the boc,After I call tonConnectUI.sendTransaction(transaction) #231

Open
1 task done
longqingzhao opened this issue Aug 12, 2024 · 0 comments
Open
1 task done
Assignees
Labels
question Further information is requested

Comments

@longqingzhao
Copy link

Your Question

After I use tonConnectUI.sendTransaction(transaction) to transfer ton, I can get boc。But to transfer jetton, I got undefined。so how can I get jetton After tonConnectUI.sendTransaction(transaction)

Context

I want to create an SDK to provide an interface for our business. They only need to provide relevant parameters without worrying about whether it is ton or jetton. Then, I will synchronize all the transfer and verification logic in the SDK. After the transfer is successful and verified, it will be returned to the business layer

What have you tried so far?

I tried all the ways I could. For example, the official website https://docs.ton.org/ For example, cloning all SDK source code to collect and parse relevant traces of returned Boc

Relevant Code or Commands

async function sendTransaction({
                                 amount,
                                 comment,
                                 toAddress,
                                 contractAddress,
                                 gasFee,
                                 repeat = 10,
                                 interval = 60 * 1000
                               }) {
  if (tonConnectUI === undefined) throw new Error('wallet connect is not initialized')
  if (!comment || comment.length === 0) {
    comment = `${Date.now()}`
  }
  const toRealAddress = await getContractAddress(toAddress)
  const realAddress = await getContractAddress(tonConnectUI?.wallet?.account?.address)
  const conRealAddress = await getContractAddress(realAddress, contractAddress)
  let payload = beginCell()
  const transaction = {
    validUntil: Math.floor(Date.now() / 1000) + 360
  }
  if (contractAddress) {
    payload = payload.storeUint(0xf8a7ea5, 32)
      .storeUint(0, 64)
      .storeCoins(toNano(amount))
      .storeAddress(toRealAddress)
      .storeAddress(realAddress)
      .storeUint(0, 1)
      .storeCoins(toNano(0.01))
      .storeUint(0, 1)
      .storeUint(0, 32)
      .storeStringTail(`${comment}`)
      .endCell()
      .toBoc()
      .toString('base64')
  } else {
    payload = payload.storeUint(0, 32)
      .storeStringTail(comment)
      .endCell()
      .toBoc()
      .toString('base64')
  }
  transaction.messages = [
    {
      address: conRealAddress.toString(),
      amount: toNano(contractAddress ? gasFee : amount).toString(),
      payload
    }
  ]
  // 发送
  const ddd = tonConnectUI.sendTransaction(transaction)
  console.log('boc', JSON.stringify(ddd))

  // let transCount = 0
  // const c = await client()
  // const needOp = contractAddress ? 0x7362d09c.toString(16) : undefined
  // const fun = (tr) => {
  //   try {
  //     const slice = tr.inMessage.body.beginParse()
  //     if (needOp) {
  //       const cop = slice.loadUint(32).toString(16)
  //       if (cop !== needOp) {
  //         return false
  //       }
  //       slice.loadUint(64)
  //       slice.loadCoins()
  //       slice.loadAddress().toString()
  //       slice.loadBit()
  //       slice.loadUint(32).toString(16)
  //     } else {
  //       slice.loadUint(32)
  //     }
  //     const currentComment = slice.loadStringTail()
  //     return comment === currentComment
  //   } catch (e) {
  //     console.log(e)
  //     return false
  //   }
  // }
  // while (transCount++ < repeat) {
  //   const transactions = await c.getTransactions(Address.parse(toAddress), { limit: 10 })
  //   const tr = transactions.find(tr => fun(tr))
  //   if (tr) {
  //     return tr
  //   }
  //   await new Promise(resolve => setTimeout(resolve, interval))
  // }
  return null
}

Documentation Check

  • Yes, I have checked the documentation.
@longqingzhao longqingzhao added the question Further information is requested label Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants