Skip to content

Instantly share code, notes, and snippets.

@dsemenovsky
Created June 1, 2018 23:59
Show Gist options
  • Save dsemenovsky/50f30eda9b096902028de3ef8afa78bc to your computer and use it in GitHub Desktop.
Save dsemenovsky/50f30eda9b096902028de3ef8afa78bc 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