Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dodikk/64409f9149da5964e8653237fb8ef5fb to your computer and use it in GitHub Desktop.
Save dodikk/64409f9149da5964e8653237fb8ef5fb to your computer and use it in GitHub Desktop.
Confirm Ethereum transaction
function confirmEtherTransaction(txHash, confirmations = 10) {
setTimeout(async () => {
// Get current number of confirmations and compare it with sought-for value
const trxConfirmations = await getConfirmations(txHash)
console.log('Transaction with hash ' + txHash + ' has ' + trxConfirmations + ' confirmation(s)')
if (trxConfirmations >= confirmations) {
// Handle confirmation event according to your business logic
console.log('Transaction with hash ' + txHash + ' has been successfully confirmed')
return
}
// Recursive call
return confirmEtherTransaction(txHash, confirmations)
}, 30 * 1000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment