Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
How can I wait for transaction to confirm using TonWeb?

I'm writing a simple DApp on TON blockchain and using the tonweb JavaScript library to interact with it.

I need to first send a transaction, and then after it confirms on chain, perform some other code in JavaScript.

Example:

await ton.send('ton_sendTransaction', [{
        to: 'some address',
        value: '1000'
    }]
)
// wait for tx to confirm on chain
console.log('Done!')

I don't know how to wait for a transaction's confirmation.

4
4
Posted 2 years ago
Edited one year ago
Daniil Sedov
233 × 6 Administrator
Votes Newest

Answers


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!')
3
3
Posted 2 years ago
Edited 2 years ago
Daniil Sedov
233 × 6 Administrator
-1
-1

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.

Slava Fomin   2 years ago Report
-1
-1

@<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

Daniil Sedov   2 years ago Report
25K Views
1 Answer
2 years ago
one year ago
Tags