Created
May 9, 2021 00:21
-
-
Save Turupawn/546a5dc4575e9507171153af38b3a77e to your computer and use it in GitHub Desktop.
revert transaction reason
This file contains hidden or 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
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