Hi, I’m coding at Swaap a quite standard web3 application. I sometimes have errors because of user (like “transaction underpriced”), sometimes because of the server (execution reverted).
My code is close to Uniswap frontend, but after an error, I’m not able to have a clear object. It’s a kind of string with text then escaped JSON
try {
newShareWei = await api.viewOneAssetJoinShare(token, amount)
} catch (error: any) {
// error is not a good object
setErrorMessage((extractErrorMessage(error)))
}
...
// I do nothing fancy in the function
async viewOneAssetJoinShare(token: Token, amount: Wei): Promise<Wei> {
return await this.contract.methods
.getJoinswapExternAmountInMMM(token.address, amount)
.call({ from: this.account })
}
I receive error in this form (note the negative error code )
{
"code": -32603,
"message": "[ethjs-query] while formatting outputs from RPC '{\"value\":{\"code\":-32603,\"data\":{\"code\":-32000,\"message\":\"transaction underpriced\"}}}'",
"stack": "Error: [ethjs-query] while formatting outputs from RPC '{\"value\":{\"code\":-32603,\"data\":{\"code\":-32000,\"message\":\"transaction underpriced\"}}}'"
}
or this one where all I want is the 44
code sent by solidity:
"Internal JSON-RPC error.\n{\n \"code\": 3,\n \"message\": \"execution reverted: 44\",\n \"data\": \"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000023434000000000000000000000000000000000000000000000000000000000000\"\n}"
Do you have any idea on how to have correctly the object directly ?
I’m also afraid that it would be different with Ledger, Coinbase Wallet or others. And on top of that, reponse is different from Rinkeby and Polygon probably because JSON-RPC endpoints are slightly differents.
If you have an article to get best practices …