I am trying to understand why an ethereum transaction reverted by using getReverReason() from eth-revert-reason. I first tried using their example which is:
console.log(await getRevertReason('0x6ea1798a2d0d21db18d6e45ca00f230160b05f172f6022aa138a0b605831d740'))
but I get the error "await is only valid in async function". When I tried to run it inside the async function as below:
const Web3 = require("web3");
const ethers = require('ethers');
const getRevertReason = require('eth-revert-reason');
const txHash = '0x6ea1798a2d0d21db18d6e45ca00f230160b05f172f6022aa138a0b605831d740'
// Failed with revert reason "Failed test"
async function reason() {
await getRevertReason(txHash)
}
console.log(reason())
I always get the same result, regardless of the Transaction Hash:
Error: Unable to decode revert reason.
Could you please help me?