Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-getClient-multichain-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@wagmi/core": patch
---

fix(core): prevent distributive conditional type in `GetClientReturnType`

Wrap the conditional in `GetClientReturnType` with tuple types to prevent TypeScript from distributing over multi-chain `resolvedChainId` unions. This allows the client returned by `getClient` to be passed directly into viem actions like `waitForTransactionReceipt`, `getBlock`, and `getTransaction` when the config has multiple chains.
23 changes: 23 additions & 0 deletions packages/core/src/actions/getClient.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { chain, config } from '@wagmi/test'
import { http } from 'viem'
import {
getBlock,
getTransaction,
waitForTransactionReceipt,
} from 'viem/actions'
import { arbitrumNova, optimism } from 'viem/chains'
import { expectTypeOf, test } from 'vitest'

import { createConfig } from '../createConfig.js'
import { getClient } from './getClient.js'

test('default', () => {
Expand All @@ -25,3 +33,18 @@ test('behavior: unconfigured chain', () => {
})
expectTypeOf(client).toEqualTypeOf<undefined>()
})

test('behavior: viem actions with multi-chain client', () => {
const twoChainConfig = createConfig({
chains: [arbitrumNova, optimism],
transports: {
[arbitrumNova.id]: http(),
[optimism.id]: http(),
},
})
const client = getClient(twoChainConfig)

waitForTransactionReceipt(client, { hash: '0x' })
getBlock(client)
getTransaction(client, { hash: '0x' })
})
2 changes: 1 addition & 1 deletion packages/core/src/actions/getClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type GetClientReturnType<
? chainId
: config['chains'][number]['id']
: config['chains'][number]['id'] | undefined,
> = resolvedChainId extends config['chains'][number]['id']
> = [resolvedChainId] extends [config['chains'][number]['id']]
? Compute<
Client<
config['_internal']['transports'][resolvedChainId],
Expand Down