Created
June 1, 2018 23:59
-
-
Save dsemenovsky/50f30eda9b096902028de3ef8afa78bc to your computer and use it in GitHub Desktop.
Confirm Ethereum transaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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