From c5e7e1d08659457f11bebac48158fc8821290800 Mon Sep 17 00:00:00 2001 From: lianqq <2088486180@qq.com> Date: Sun, 24 May 2026 13:54:20 +0800 Subject: [PATCH] fix(core): prevent distributive conditional type in GetClientReturnType Wrap the conditional in `GetClientReturnType` with tuple types to stop TypeScript from distributing over multi-chain `resolvedChainId` unions. This allows the client returned by `getClient` to be passed directly into viem actions (waitForTransactionReceipt, getBlock, getTransaction) when the config has multiple chains. Closes #3635 --- .changeset/fix-getClient-multichain-type.md | 7 ++++++ packages/core/src/actions/getClient.test-d.ts | 23 +++++++++++++++++++ packages/core/src/actions/getClient.ts | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .changeset/fix-getClient-multichain-type.md diff --git a/.changeset/fix-getClient-multichain-type.md b/.changeset/fix-getClient-multichain-type.md new file mode 100644 index 0000000000..58b858ce5a --- /dev/null +++ b/.changeset/fix-getClient-multichain-type.md @@ -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. diff --git a/packages/core/src/actions/getClient.test-d.ts b/packages/core/src/actions/getClient.test-d.ts index f64cbae2ce..01ae80e3ec 100644 --- a/packages/core/src/actions/getClient.test-d.ts +++ b/packages/core/src/actions/getClient.test-d.ts @@ -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', () => { @@ -25,3 +33,18 @@ test('behavior: unconfigured chain', () => { }) expectTypeOf(client).toEqualTypeOf() }) + +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' }) +}) diff --git a/packages/core/src/actions/getClient.ts b/packages/core/src/actions/getClient.ts index ba78cafa34..2ae38e462b 100644 --- a/packages/core/src/actions/getClient.ts +++ b/packages/core/src/actions/getClient.ts @@ -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],