Skip to content

Conversation

@frolic
Copy link
Contributor

@frolic frolic commented Aug 16, 2024

I have a contract that can revert with a custom error. In current version of viem, when I call this function with writeContract, I get an obscure error like:

EstimateGasExecutionError: Execution reverted with reason:  h.

Estimate Gas Arguments:
  from:                  0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
  to:                    0x8d8b6b8414e1e3dcfd4168561b9be6bd3bf6ec4b
  data:                  0x8da798da0000000000000000000000002ff959c7d78a64356c28bcf5f6e3cd56f1463901
00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000
000000000000
  maxFeePerGas:          0 gwei
  maxPriorityFeePerGas:  0 gwei
  nonce:                 17

Details: execution reverted:  h
Version: [email protected]

(note the h in the revert is actually the 4 byte string as utf-8 rather than hex encoding)

With this change, it should now look more like:

ContractFunctionExecutionError: The contract function "installModule" reverted.

Error: Module_AlreadyInstalled()
 
Contract Call:
  address:   0x8d8b6b8414e1e3dcfd4168561b9be6bd3bf6ec4b
  function:  installModule(address module, bytes encodedArgs)
  args:                   (0x2FF959C7D78A64356C28Bcf5F6E3cD56f1463901, 0x)
  sender:    0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

Docs: https://viem.sh/docs/contract/simulateContract
Version: 2.19.4

See also #732 and #1281


PR-Codex overview

This PR improves error handling in the writeContract function, adds new error types, and enhances contract function execution error messages.

Detailed summary

  • Improved error handling in writeContract
  • Added ParseAccountErrorType and GetContractErrorReturnType
  • Enhanced contract function execution error messages
  • Updated tests with new error handling scenarios

The following files were skipped due to too many changes: src/actions/wallet/writeContract.test.ts, src/op-stack/actions/proveWithdrawal.test.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@changeset-bot
Copy link

changeset-bot bot commented Aug 16, 2024

🦋 Changeset detected

Latest commit: 22b9bea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Aug 16, 2024

@holic is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@frolic frolic force-pushed the holic/write-contract-errors branch from 506e054 to 4530187 Compare August 16, 2024 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants