You can save transaction hash before sending it and then query Toncenter API method getTransactionByInMessageHash to check if transaction with such hash was confirmed or not
Example:
// Sleep function:
const sleep = ms => new Promise(r => setTimeout(r, ms))
// `msg` is a Cell containing your external message
// Convert message Cell to BOC String
const boc = await msg.toBoc(false)
// Calculate it's hash
const hash = tonweb.utils.bytesToBase64(await msg.hash())
// Send message and run a loop until transaction with that hash confirms
await tonweb.sendBoc(boc)
var txs = []
while (txs.length == 0) {
await sleep(1200) // some delay between API calls
const resp = await fetch('https://toncenter.com/api/index/getTransactionByInMessageHash?&include_msg_body=false&msg_hash=' + encodeURIComponent(hash))
txs = await resp.json()
}
console.log('Done!')
What if several transactions will be processed by the account between calls to the getTransactions()
? You will probably match an incorrect transaction. You need to implement a more strict transaction matching for this to work reliably.
@<1485966303708581888|Slava Fomin> Yes you're right. I mentioned in the answer that it's just a simple approach. I'll update the answer now with more explanations
Please add the syntax highlighting to your code. ```js code ```