How do you parse returned json rpc errors from a failed transaction to get the underying revert message if any? I'm on frontend.
example:
try {
await contract.methods.someMethod().send({from: account})
} catch(e) {
console.log(e)
}
the error looks like this:
Error: Internal JSON-RPC error.
{
"code": 3,
"message": "execution reverted: blah blah",
"data": "0x12313532492somethingsomething"
}
I need to get the "execution reverted: blah blah" message
- I tried:
console.log(e.message)
Internal JSON-RPC error.
{
"code": 3,
"message": "execution reverted: blah blah",
"data": "0x12313532492somethingsomething"
}
console.log(JSON.parse(e))
JSON.parse: unexpected character at line 1 column 1 of the JSON data
Error(string)
andPanic(uint256)
. You could define your own errors types.