Skip to content

Should client.multicall validate that functionNames are in the ABI? #377

Closed Answered by tmm
hammeiam asked this question in Question
Discussion options

You must be logged in to vote

This is a limitation of TypeScript at the moment and how it handles higher-order functions. See microsoft/TypeScript#29841 Workaround is to cast each mapped value using ContractFunctionConfig:

import type { ContractFunctionConfig } from 'viem'

const res = await publicClient.multicall({
  allowFailure: false,
  contracts: tokenAddresses.map(
    (x) =>
      ({
        address: x,
        abi: erc20Abi,
        functionName: 'balanceOf',
        args: ['0x'],
      } as ContractFunctionConfig<
        typeof erc20Abi,
        'balanceOf',
        'pure' | 'view'
      >),
  ),
})

TypeScript Playground

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@tmm
Comment options

tmm Apr 15, 2023
Maintainer

Answer selected by tmm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants