Skip to content

Instantly share code, notes, and snippets.

@Turupawn
Created May 9, 2021 00:21
Show Gist options
  • Save Turupawn/546a5dc4575e9507171153af38b3a77e to your computer and use it in GitHub Desktop.
Save Turupawn/546a5dc4575e9507171153af38b3a77e to your computer and use it in GitHub Desktop.
revert transaction reason
async function getRevertReason(txHash){
const tx = await web3.eth.getTransaction(txHash)
var result = await web3.eth.call(tx, tx.blockNumber)
result = result.startsWith('0x') ? result : `0x${result}`
if (result && result.substr(138)) {
const reason = web3.utils.toAscii(result.substr(138))
console.log('Revert reason:', reason)
return reason
} else {
console.log('Cannot get reason - No return value')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment