You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hello
I wanted to make a function that after the user accepts the transaction
Based on the boc that the sendTransaction method returns, I will measure whether it has been deposited or not
I want to use this in two places
First, after accepting the transaction by the user, check and tell the user whether the transaction was done correctly or not
And secondly, the server side checks whether the transaction is successful or not
If it is successful, it will be added to the user's inventory
I wrote this code and it works
But it has many problems and cannot be used in real programs
I would be grateful if you could help me
import{TonConnectUI}from"@tonconnect/ui";import{v4asuuidv4}from"uuid"import{beginCell,toNano}from"@ton/ton";importTonWebfrom"tonweb";consttonconnect=newTonConnectUI({manifestUrl: 'https://..../manifest.json',buttonRootId: 'connect'})consttonweb=newTonWeb(newTonWeb.HttpProvider('https://toncenter.com/api/v2/jsonRPC',{apiKey: '....'}))functionMakeTxInvoice(){consttxId=uuidv4()constbody=beginCell().storeUint(0,32).storeStringTail(txId).endCell();return{txid : txId,validUntil: Math.floor(Date.now()/1000)+360,messages: [{address: "UQCM4-pSTwwn-JIGKBb4FlilvEVAkdBUlJTykNpWBUtQ-VHm",amount: toNano(0.05).toString(),},{address: "UQCM4-pSTwwn-JIGKBb4FlilvEVAkdBUlJTykNpWBUtQ-VHm",amount: toNano(0.05).toString(),payload: body.toBoc().toString("base64")}]}}tonconnect.onStatusChange(async(state)=>{if(state){constTx=MakeTxInvoice()consttxId=Tx.txidconstresult=awaittonconnect.sendTransaction(Tx)awaitcheckTransaction(txId);}})asyncfunctioncheckTransaction(txId){constmaxAttempts=20;letattempts=0;while(attempts<maxAttempts){constlastTx=awaittonweb.getTransactions(tonconnect.account.address,1);constlastTxID=lastTx[0].in_msg.message;if(lastTxID===txId){alert('Transaction confirmed!');return;}attempts++;awaitnewPromise(resolve=>setTimeout(resolve,5000));}alert('Transaction not confirmed within the maximum number of attempts.');}```
### DocumentationCheck-[X]Yes,Ihavecheckedthedocumentation.
The text was updated successfully, but these errors were encountered:
Your Question
hello
I wanted to make a function that after the user accepts the transaction
Based on the boc that the sendTransaction method returns, I will measure whether it has been deposited or not
I want to use this in two places
First, after accepting the transaction by the user, check and tell the user whether the transaction was done correctly or not
And secondly, the server side checks whether the transaction is successful or not
If it is successful, it will be added to the user's inventory
I wrote this code and it works
But it has many problems and cannot be used in real programs
I would be grateful if you could help me
Context
i am tying make a online shop can pay with ton
What have you tried so far?
https://medium.com/coinmonks/understanding-ton-transactions-how-to-track-transaction-results-and-utilize-tonclient-b992336eb3a3
https://docs.ton.org/develop/dapps/asset-processing/#check-contracts-transactions
Relevant Code or Commands
The text was updated successfully, but these errors were encountered: