Best way to wait for a transaction to finish

What’s the best way to wait for a transaction to finish in moralis?

Right now, if you use runContractFunction from useWeb3Contract you can use the onSuccess param to do something after the transaction was submitted. What’s the best way to do something after a transaction has 1 block confirmations? (Or X confirmations)

Right now, I know I can listen for events manually… but it feels odd.

For useWeb3ExecuteFunction , you can have it in such way.

onSuccess: (tx) =>
  tx.wait().then((finalTx) => {

For X confirmations, you can have tx.wait(X).then(....

But for runContractFunction, it’s used for read only function which doesn’t require any confirmation, so onSuccess is for successful call and onErrror is to handle error

You can use the useWeb3ExecuteFunction hook to execute on-chain functions, both read and write, but runContractFunction Runs a given function of a contract ABI and returns read-only data.

1 Like

Yeah, right after I posted this I face palmed, that’s what I’d been doing in my code lol