1

Hello I'm interacting with a smart contract and I have require function in the solidity smart contract, I would like to show these messages properly formatted in the console when I log the error I get type object but I cannot acces properties can someone shed light, thanks ahead!

console.log(e.message)

Error: execution reverted: Already claimed
{
  "originalError": {
    "code": 3,
    "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f416c726561647920636c61696d65640000000000000000000000000000000000",
    "message": "execution reverted: Already claimed"
  }
}
    at Object._fireError (index.js?5ba3:49)
    at sendTxCallback (index.js?7789:539)
    at cb (util.js?3022:689)
    at callbackifyOnRejected (util.js?3022:666)
    at eval (process.js?4362:5)

enter image description here

1 Answer 1

2

I am working on a similar issue, not sure if you have figured this out, but some of the actual error message data comes back as a stringified JSON object. In my experience those errors usually come with code: and message: keys inside. You would to take say error.message, and JSON.parse() it.

For me the issue is I need to build an error handler to handle the 3 object formats i've encountered. Ideally I'm going to build it to handle RPC errors plus others. It kind of depends where the tx reverts too. Hope that helps someone.

2
  • 1
    I did manage to fix this thank you! return common.Hash{}, &rpc.CustomError{Code: -32602, ValidationError: "Your error message"} Commented Sep 9, 2022 at 10:32
  • Yay! Glad to hear!! Commented Oct 18, 2022 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.