-
Notifications
You must be signed in to change notification settings - Fork 8
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
[Question] Error format depending on the EVM backend ? #42
Comments
Hey @challet ! Indeed Ganache is probably changing the format a bit, but maybe there is a way to make it compatible. Are you using https://github.com/trufflesuite/ganache#as-an-ethersjs-provider ? Could you share some code around how you are populating and executing transactions ? |
Actually no, because I'm using ganache CLI and then connecting my dapp through @wagmi/core publicProvider : it wraps an Ethers StaticJsonRpcProvider and doesn't involve any error handling. This is the code I'm using (several parts pasted together, hopefully without omission): import { configureChains, createClient, getContract, getProvider, prepareWriteContract, writeContract, InjectedConnector } from '@wagmi/core'
import { publicProvider } from '@wagmi/core/providers/public'
import { localhost } from '@wagmi/core/chains'
import { getParsedEthersError } from '@enzoferey/ethers-error-parser'
import type { Contract } from 'ethers'
import type { EthersError } from '@enzoferey/ethers-error-parser'
// configure wagmi
const { provider, chains } = configureChains(
[localhost],
[publicProvider()]
)
// it creates a singleton that will be used internally by other wagmi functions
createClient({
autoConnect: true,
connectors: [new InjectedConnector({ chains })],
provider
})
// […]
const contract: Contract = await getContract({
address, abi, signerOrProvider: getProvider()
})
try {
const config = await prepareWriteContract({ // this function calls `estimateGas`
address: contract.address,
abi: contract.interface.fragments,
functionName: 'myFunction' // method of the contract that is reverting the transaction
})
trx = await writeContract(config)
} catch (e) {
console.log(getParsedEthersError(e as EthersError))
} I'm trying to dig into ethers to see where it can differ from the expected format (maybe in the providers, maybe in the backend). |
Tracing it back into Metamask, that is the raw error received from the backend being re-thrown without modification by ethers or a provider. |
In fact, I see two scenarios here for the same error but with a different format (with or without Ganache, even though there might still be an other layer of difference in using it). call to
|
Thanks for all the details @challet ! 🙏🏻 Maybe indeed we do not support the |
Imho, the problem is on the ethers side where it should throw the same error for both cases. There is no hurry and please consider it a discussion in progress as I'm a bit confused in how the various providers and signers work, especially if they all behave the same. I opened a discussion on the ethers repo about it : ethers-io/ethers.js#3618 |
Hello, while using Ganache as a development backend, some errors are not handled as expected.
For instance with the following one (the context is a call to ethers estimateGas method which makes a dry run of the transaction and so can throw similar errors as the actual transaction):
It is parsed as
{ errorCode: 'UNKNOWN_ERROR', context: '-32603' }
while imho it should return theEXECUTION_REVERTED
one :ethers-error-parser/lib/constants.ts
Line 6 in d4e452b
The text message looks really specific to Ganache and I'm wondering whether the whole error structure is also specific to it. How could it be then handled by the error parser ?
The text was updated successfully, but these errors were encountered: