wevm / viem

TypeScript Interface for Ethereum
https://viem.sh
Other
2.56k stars 847 forks source link

Simulation incorrectly reports `ContractFunctionExecutionError` instead of `ContractFunctionRevertedError` #3020

Closed TilakMaddy closed 2 hours ago

TilakMaddy commented 2 hours ago

Check existing issues

Viem Version

2.21.40

Current Behavior

Code

try {
    const simulation = await this.client.simulateContract({
        abi: faucetAbi,
        address: FAUCET_ADDRESS,
        functionName: 'mint',
        chain: arbitrum,
        account: this.address,
        args: [],
      });
    console.log(simulation);

    const hash = await this.client.writeContract({
        abi: faucetAbi,
        address: FAUCET_ADDRESS,
        functionName: 'mint',
        chain: arbitrum,
        account: this.address,
    })
    console.log(hash)
    await this.readTokenBalance()
} catch (err) {
    console.log(err);
    if (err instanceof BaseError) {
        const revertErr = err.walk(err => err instanceof ContractFunctionRevertedError);
        if (revertErr instanceof ContractFunctionRevertedError) {
            const errorName = revertErr.data?.errorName ?? ''
            console.log(errorName);
        }
    }
}
ContractFunctionExecutionError: Data size of 4 bytes is too small for given parameters.

Params: ()
Data:   0x7ec6cd58 (4 bytes)

Contract Call:
  address:   0x16D218938416d58C58CaC586D57F27fD8CAfBec1
  function:  mint()
  sender:    0x72598C4C5cFD3685E2F908FC3D3B9DF7320149D4

Docs: https://viem.sh/docs/contract/simulateContract
Version: viem@2.21.40
    at getContractError (chunk-TZAFQCCV.js?v=3abc04ce:889:10)
    at simulateContract (chunk-TZAFQCCV.js?v=3abc04ce:4904:11)
    at async WalletConnection.mintTokensFromFaucet (wallet.svelte.ts:125:19)
    at async HTMLButtonElement.handleMintRequest [as __click] (+page.svelte:18:25)Caused by: AbiDecodingDataSizeTooSmallError: Data size of 4 bytes is too small for given parameters.

Params: ()
Data:   0x7ec6cd58 (4 bytes)

Version: viem@2.21.40
    at decodeAbiParameters (chunk-ZF6VVK62.js?v=3abc04ce:2661:11)
    at decodeFunctionResult (chunk-D4AFAUKJ.js?v=3abc04ce:1482:18)
    at simulateContract (chunk-TZAFQCCV.js?v=3abc04ce:4884:20)
    at async WalletConnection.mintTokensFromFaucet (wallet.svelte.ts:125:19)
    at async HTMLButtonElement.handleMintRequest [as __click] (+page.svelte:18:25)

Expected Behavior

I'm unable to make sense of how 4 bytes is too small data size for an empty parametered function.

AbiDecodingDataSizeTooSmallError: Data size of 4 bytes is too small for given parameters.

Steps To Reproduce

No response

Link to Minimal Reproducible Example

No response

Anything else?

No response

jxom commented 2 hours ago

Hard to tell what's going on without a minimal reproducible example, but likely your ABI expects an input for the "mint" function.

github-actions[bot] commented 2 hours ago

Hello @TilakMaddy.

Please provide a minimal reproduction using StackBlitz, TypeScript Playground (for type issues), or a separate minimal GitHub repository.

Minimal reproductions are required as they save us a lot of time reproducing your config/environment and issue, and allow us to help you faster.

Once a minimal reproduction is added, a team member will confirm it works, then re-open the issue.

TilakMaddy commented 2 hours ago

No, the mint function has no parameters. I'll try to create a minimal reproducible example tomorrow and link it here

Thanks