Skip to content

Instantly share code, notes, and snippets.

@JhonatanHern
Created December 6, 2022 18:36
Show Gist options
  • Save JhonatanHern/648766f4fcd27f3fc2b102bf7991eb9f to your computer and use it in GitHub Desktop.
Save JhonatanHern/648766f4fcd27f3fc2b102bf7991eb9f to your computer and use it in GitHub Desktop.
const sleep = (milliseconds) => { return new Promise(resolve => setTimeout(resolve, milliseconds)) }
const waitUntilTransactionIsConfirmed = hash => new Promise(async (succ, err) => {
while(true) {
const transaction = await web3.eth.getTransactionReceipt(hash)
if (transaction) {
console.log('transaction status: ', transaction);
return (transaction.status ? succ : err)(transaction)
}
await sleep(1000) // 1 second
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment