Reputation: 443
I was trying to find out if I could wait for the transaction to be mined from just transaction hash using node.js backend. I found this piece of code:
const isTransactionMined = async(transactionHash) => {
const txReceipt = await provider.getTransactionReceipt(transactionHash);
if (txReceipt && txReceipt.blockNumber) {
return txReceipt;
}
}
But the problem with is code is that it returns nothing if the transaction is pending. I don't have the access to the signer object. So, is there a way to wait for the transaction to be mined with only knowing the tx hash?
Upvotes: 1
Views: 4097
Reputation: 49671
You could use provider.getTransaction
If a transaction has not been mined, this method will search the transaction pool. Various backends may have more restrictive transaction pool access (e.g. if the gas price is too low or the transaction was only recently sent and not yet indexed) in which case this method may also return null.
const txReceipt = await provider.getTransaction(transactionHash)
Upvotes: 4