Skip to content

Using Viem within another library and supporting the same type inference from Viem #238

Answered by fubhy
sammdec asked this question in Question
Discussion options

You must be logged in to vote

After toying around with the different options, I've concluded that (for now), the best option for an SDK imho is to not try and abstract away the signing & sending of transactions but simply provide convenience functions to produce the right, typed inputs for the viem client functions. I'm doing sth. like this now:

// ./utils/viem.ts

import type { Abi, Narrow } from "abitype";
import type { ExtractArgsFromAbi, ExtractFunctionNameFromAbi } from "viem";

export type FunctionParams<TAbi extends Abi | readonly unknown[] = Abi, TFunctionName extends string = string> = {
  abi: Narrow<TAbi>;
  functionName: ExtractFunctionNameFromAbi<TAbi, TFunctionName>;
} & ExtractArgsFromAbi<TAbi, TFunctio…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jxom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants