Created
April 1, 2020 23:56
-
-
Save JesseAbram/a4eb92a241de61acaa910d15d06914e9 to your computer and use it in GitHub Desktop.
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
// taken and modified from here https://gist.github.com/gluk64/fdea559472d957f1138ed93bcbc6f78a#file-reason-js | |
// This is universal, works with Infura -- set provider accordingly | |
const ethers = require('ethers') | |
const { TEAMS_ENDPOINT } = require("./credentials.js") | |
const provider = new ethers.providers.JsonRpcProvider(TEAMS_ENDPOINT); | |
function hex_to_ascii(str1) { | |
var hex = str1.toString(); | |
var str = ''; | |
for (var n = 0; n < hex.length; n += 2) { | |
str += String.fromCharCode(parseInt(hex.substr(n, 2), 16)); | |
} | |
return str; | |
} | |
async function reason(hash) { | |
var args = process.argv.slice(2) | |
console.log('tx hash:', hash) | |
let tx = await provider.getTransaction(hash) | |
// console.log(tx) | |
if (!tx) { | |
console.log('tx not found') | |
} else { | |
let code | |
try{ | |
code = await provider.call(tx, tx.blockNumber) | |
} catch (e) { | |
console.log("here ==========",e) | |
let reason = hex_to_ascii(e.data.substr(9)) | |
console.log('revert reason:', reason) | |
} | |
} | |
} | |
reason("0x686805a6f0daff26e8f46a5dcbfcce0f85e64f1809750997df58f0d7d5cc96ff") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment