Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

estimateTransactionGasLimit hides errors from the caller #1080

Open
shioju opened this issue Feb 8, 2023 · 2 comments
Open

estimateTransactionGasLimit hides errors from the caller #1080

shioju opened this issue Feb 8, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@shioju
Copy link

shioju commented Feb 8, 2023

Describe the bug
estimateTransactionGasLimit hides errors from the caller

To Reproduce
We're using useContractFunction to call a smart contract function. In this instance, we're expecting the function to revert with a custom error, and want to catch it and display an appropriate error message to the user.

However, we only see the cannot estimate gas error in the browser console, but unable to catch the error where we're calling send.
screenshot-20230208-12:34:23

Relevant part of useContractFunction's send which checks gas estimate:
screenshot-20230208-12:26:02

Relevant part of estimateTransactionGasLimit which catches the error but does not throw it to the caller:
screenshot-20230208-12:39:34

@shioju shioju added the bug Something isn't working label Feb 8, 2023
@shioju
Copy link
Author

shioju commented Feb 8, 2023

We realized that the useContractFunction state has an errorHash which can be mapped back to the custom error defined in the smart contract (e.g. using ethers getError function)

@Craigson
Copy link

Craigson commented Feb 21, 2023

@shioju , I'm experiencing a similar issue - however the state only provides status: "PendingSignature" as the user has not yet interacted with their wallet.

They cannot confirm the TX as the gas estimate is 0, and clicking reject does not return an error hash:

See the error below:

usePromiseTransaction.ts:51 Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted", method="estimateGas", transaction={"from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","to":"0x0C8E79F3534B00D9a3D4a856B665Bf4eBC22f2ba","value":{"type":"BigNumber","hex":"0x0de0b6b3a763e700"},"data":"0x7223a3c30000000000000000000000000000000000000000000000000de0b6b3a763e700000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000151800000000000000000000000000000000000000000000000000000000000000000","accessList":null}, error={"code":-32603,"message":"Internal JSON-RPC error.","data":{"code":3,"message":"execution reverted","data":"0x7baa7dfa"},"stack":"{\n  \"code\": -32603,\n  \"message\": \"Internal JSON-RPC error.\",\n  \"data\": {\n    \"code\": 3,\n    \"message\": \"execution reverted\",\n    \"data\": \"0x7baa7dfa\"\n  },\n  \"stack\": \"Error: Internal JSON-RPC error.\\n    at new n (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-1.js:12:23059)\\n    at a (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-1.js:12:25815)\\n    at Object.internal (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-1.js:12:26425)\\n    at u (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-1.js:29:42701)\\n    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-1.js:29:43730\\n    at async chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-4.js:10:47625\"\n}\n  at new n (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-1.js:12:23059)\n  at a (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-1.js:12:25815)\n  at Object.internal (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-1.js:12:26425)\n  at u (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-1.js:29:42701)\n  at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-1.js:29:43730\n  at async chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-4.js:10:47625"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.7.2)
    at Logger.makeError (index.ts:269:1)
    at Logger.throwError (index.ts:281:1)
    at checkError (json-rpc-provider.ts:78:1)
    at Web3Provider.<anonymous> (json-rpc-provider.ts:642:1)
    at Generator.throw (<anonymous>)

I need some way to access the error so that I can parse it using the interface, but it never reaches the dapp state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants