最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Typescript type for viem WalletClient with "account" defined? - Stack Overflow

programmeradmin4浏览0评论

When using the viem library's createWalletClient function, you can optionally provide an account parameter (to hoist it), and thereafter it's not needed to be specified on calls like walletClient.writeContract().

In Typescript, viem exports a WalletClient type, but it is defined as having its account be optional. I have an helper function that always returns a WalletClient object with account set. How can I annotate the helper function so all calling modules know the account is already specified, and typescript stops telling me to add it into subsequent writeContract() calls?

The viem WalletClient type does take some generics parameters, but I cannot figure a concise way to specify "the account is set to an address value" using them.

When using the viem library's createWalletClient function, you can optionally provide an account parameter (to hoist it), and thereafter it's not needed to be specified on calls like walletClient.writeContract().

In Typescript, viem exports a WalletClient type, but it is defined as having its account be optional. I have an helper function that always returns a WalletClient object with account set. How can I annotate the helper function so all calling modules know the account is already specified, and typescript stops telling me to add it into subsequent writeContract() calls?

The viem WalletClient type does take some generics parameters, but I cannot figure a concise way to specify "the account is set to an address value" using them.

Share Improve this question edited Mar 17 at 4:37 MidnightLightning asked Mar 17 at 4:20 MidnightLightningMidnightLightning 6,9387 gold badges47 silver badges72 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

For a WalletClient that has an RPC connection (Transport), target chain, and address defined, the following type definition creates an alias for that:

export type ConnectedWalletClient = WalletClient<Transport, Chain, Account, undefined>

Having that be the type that the helper function returns, and being an exported type then allows other modules to use ConnectedWalletClient as a short alias, and have Typescript not require specifying the account parameter on subsequent writeContract calls.

发布评论

评论列表(0)

  1. 暂无评论