diff --git a/.changeset/quietly-dogs-march.md b/.changeset/quietly-dogs-march.md new file mode 100644 index 0000000000..225eb43db9 --- /dev/null +++ b/.changeset/quietly-dogs-march.md @@ -0,0 +1,5 @@ +--- +'@wagmi/core': patch +--- + +Fixed `feePayer` types for Tempo chains on `sendTransaction`, `sendTransactionSync`, and `deployContract`. diff --git a/.changeset/slowly-birds-sing.md b/.changeset/slowly-birds-sing.md new file mode 100644 index 0000000000..d8a803bd88 --- /dev/null +++ b/.changeset/slowly-birds-sing.md @@ -0,0 +1,5 @@ +--- +'@wagmi/vue': patch +--- + +Fixed `feePayer` types for Tempo chains on `useSendTransaction`. diff --git a/.changeset/softly-cats-dance.md b/.changeset/softly-cats-dance.md new file mode 100644 index 0000000000..689a3d381f --- /dev/null +++ b/.changeset/softly-cats-dance.md @@ -0,0 +1,5 @@ +--- +'wagmi': patch +--- + +Fixed `feePayer` types for Tempo chains on `useSendTransaction`, `useSendTransactionSync`, `useWriteContract`, and `useWriteContractSync`. diff --git a/packages/core/src/actions/deployContract.test-d.ts b/packages/core/src/actions/deployContract.test-d.ts index b7a6a897d3..a2e75456e5 100644 --- a/packages/core/src/actions/deployContract.test-d.ts +++ b/packages/core/src/actions/deployContract.test-d.ts @@ -1,6 +1,7 @@ import { abi, bytecode, config } from '@wagmi/test' import { http } from 'viem' -import { celo, mainnet } from 'viem/chains' +import { privateKeyToAccount } from 'viem/accounts' +import { celo, mainnet, tempoLocalnet } from 'viem/chains' import { expectTypeOf, test } from 'vitest' import { createConfig } from '../createConfig.js' @@ -69,3 +70,67 @@ test('chain formatters', () => { feeCurrency: '0x', }) }) + +test('tempo feePayer', () => { + const feePayer = privateKeyToAccount( + '0x0123456789012345678901234567890123456789012345678901234567890123', + ) + + const tempoConfig = createConfig({ + chains: [tempoLocalnet], + transports: { [tempoLocalnet.id]: http() }, + }) + + deployContract(tempoConfig, { + abi: abi.bayc, + bytecode: bytecode.bayc, + args: ['Bored Ape Wagmi Club', 'BAYC', 69420n, 0n], + feePayer: true, + }) + + deployContract(tempoConfig, { + abi: abi.bayc, + bytecode: bytecode.bayc, + args: ['Bored Ape Wagmi Club', 'BAYC', 69420n, 0n], + feePayer, + }) + + const config = createConfig({ + chains: [mainnet, tempoLocalnet], + transports: { [mainnet.id]: http(), [tempoLocalnet.id]: http() }, + }) + + deployContract(config, { + chainId: tempoLocalnet.id, + abi: abi.bayc, + bytecode: bytecode.bayc, + args: ['Bored Ape Wagmi Club', 'BAYC', 69420n, 0n], + feePayer: true, + }) + + deployContract(config, { + chainId: tempoLocalnet.id, + abi: abi.bayc, + bytecode: bytecode.bayc, + args: ['Bored Ape Wagmi Club', 'BAYC', 69420n, 0n], + feePayer, + }) + + deployContract(config, { + chainId: mainnet.id, + abi: abi.bayc, + bytecode: bytecode.bayc, + args: ['Bored Ape Wagmi Club', 'BAYC', 69420n, 0n], + // @ts-expect-error + feePayer: true, + }) + + type Result = DeployContractParameters< + typeof abi.bayc, + typeof config, + typeof mainnet.id + > + expectTypeOf().not.toMatchTypeOf<{ + feePayer?: true | typeof feePayer | undefined + }>() +}) diff --git a/packages/core/src/actions/deployContract.ts b/packages/core/src/actions/deployContract.ts index 0501e7ff56..1278262a07 100644 --- a/packages/core/src/actions/deployContract.ts +++ b/packages/core/src/actions/deployContract.ts @@ -12,7 +12,7 @@ import type { ChainIdParameter, ConnectorParameter, } from '../types/properties.js' -import type { Compute } from '../types/utils.js' +import type { UnionCompute, UnionLooseOmit } from '../types/utils.js' import { getAction } from '../utils/getAction.js' import { type GetConnectorClientErrorType, @@ -28,8 +28,8 @@ export type DeployContractParameters< allArgs = ContractConstructorArgs, chains extends readonly Chain[] = SelectChains, > = { - [key in keyof chains]: Compute< - Omit< + [key in keyof chains]: UnionCompute< + UnionLooseOmit< viem_DeployContractParameters< abi, chains[key], diff --git a/packages/core/src/actions/sendTransaction.test-d.ts b/packages/core/src/actions/sendTransaction.test-d.ts index 54ce62a947..ecccf0bd49 100644 --- a/packages/core/src/actions/sendTransaction.test-d.ts +++ b/packages/core/src/actions/sendTransaction.test-d.ts @@ -1,5 +1,6 @@ import { http, parseEther } from 'viem' -import { celo, mainnet } from 'viem/chains' +import { privateKeyToAccount } from 'viem/accounts' +import { celo, mainnet, tempoLocalnet } from 'viem/chains' import { expectTypeOf, test } from 'vitest' import { createConfig } from '../createConfig.js' @@ -40,11 +41,59 @@ test('chain formatters', () => { expectTypeOf().not.toMatchTypeOf<{ feeCurrency?: `0x${string}` | undefined }>() +}) + +test('tempo feePayer', () => { + const feePayer = privateKeyToAccount( + '0x0123456789012345678901234567890123456789012345678901234567890123', + ) + + const tempoConfig = createConfig({ + chains: [tempoLocalnet], + transports: { [tempoLocalnet.id]: http() }, + }) + + sendTransaction(tempoConfig, { + to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', + value: 1n, + feePayer: true, + }) + + sendTransaction(tempoConfig, { + to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', + value: 1n, + feePayer, + }) + + const config = createConfig({ + chains: [mainnet, tempoLocalnet], + transports: { [mainnet.id]: http(), [tempoLocalnet.id]: http() }, + }) + + sendTransaction(config, { + chainId: tempoLocalnet.id, + to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', + value: 1n, + feePayer: true, + }) + + sendTransaction(config, { + chainId: tempoLocalnet.id, + to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', + value: 1n, + feePayer, + }) + sendTransaction(config, { chainId: mainnet.id, to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', - value: parseEther('0.01'), + value: 1n, // @ts-expect-error - feeCurrency: '0x', + feePayer: true, }) + + type Result = SendTransactionParameters + expectTypeOf().not.toMatchTypeOf<{ + feePayer?: true | typeof feePayer | undefined + }>() }) diff --git a/packages/core/src/actions/sendTransaction.ts b/packages/core/src/actions/sendTransaction.ts index c50e2337d5..4d5548ade4 100644 --- a/packages/core/src/actions/sendTransaction.ts +++ b/packages/core/src/actions/sendTransaction.ts @@ -16,7 +16,7 @@ import type { ChainIdParameter, ConnectorParameter, } from '../types/properties.js' -import type { Compute } from '../types/utils.js' +import type { UnionCompute, UnionLooseOmit } from '../types/utils.js' import { getAction } from '../utils/getAction.js' import { type GetConnectorClientErrorType, @@ -30,15 +30,17 @@ export type SendTransactionParameters< /// chains extends readonly Chain[] = SelectChains, > = { - [key in keyof chains]: Compute< - Omit< + [key in keyof chains]: UnionCompute< + UnionLooseOmit< viem_SendTransactionParameters, 'chain' | 'gas' > & ChainIdParameter & - ConnectorParameter + SendTransactionOverrides > -}[number] & { +}[number] + +type SendTransactionOverrides = ConnectorParameter & { /** Gas provided for transaction execution. */ gas?: TransactionRequest['gas'] | null } diff --git a/packages/core/src/actions/sendTransactionSync.test-d.ts b/packages/core/src/actions/sendTransactionSync.test-d.ts new file mode 100644 index 0000000000..ec6c846c0e --- /dev/null +++ b/packages/core/src/actions/sendTransactionSync.test-d.ts @@ -0,0 +1,99 @@ +import { http, parseEther } from 'viem' +import { privateKeyToAccount } from 'viem/accounts' +import { celo, mainnet, tempoLocalnet } from 'viem/chains' +import { expectTypeOf, test } from 'vitest' + +import { createConfig } from '../createConfig.js' +import { + type SendTransactionSyncParameters, + sendTransactionSync, +} from './sendTransactionSync.js' + +test('chain formatters', () => { + const config = createConfig({ + chains: [mainnet, celo], + transports: { [celo.id]: http(), [mainnet.id]: http() }, + }) + + type Result = SendTransactionSyncParameters + expectTypeOf().toMatchTypeOf<{ + chainId?: typeof celo.id | typeof mainnet.id | undefined + feeCurrency?: `0x${string}` | undefined + }>() + sendTransactionSync(config, { + to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', + value: parseEther('0.01'), + feeCurrency: '0x', + }) + + type Result2 = SendTransactionSyncParameters + expectTypeOf().toMatchTypeOf<{ + feeCurrency?: `0x${string}` | undefined + }>() + sendTransactionSync(config, { + chainId: celo.id, + to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', + value: parseEther('0.01'), + feeCurrency: '0x', + }) + + type Result3 = SendTransactionSyncParameters + expectTypeOf().not.toMatchTypeOf<{ + feeCurrency?: `0x${string}` | undefined + }>() +}) + +test('tempo feePayer', () => { + const feePayer = privateKeyToAccount( + '0x0123456789012345678901234567890123456789012345678901234567890123', + ) + + const tempoConfig = createConfig({ + chains: [tempoLocalnet], + transports: { [tempoLocalnet.id]: http() }, + }) + + sendTransactionSync(tempoConfig, { + to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', + value: 1n, + feePayer: true, + }) + + sendTransactionSync(tempoConfig, { + to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', + value: 1n, + feePayer, + }) + + const config = createConfig({ + chains: [mainnet, tempoLocalnet], + transports: { [mainnet.id]: http(), [tempoLocalnet.id]: http() }, + }) + + sendTransactionSync(config, { + chainId: tempoLocalnet.id, + to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', + value: 1n, + feePayer: true, + }) + + sendTransactionSync(config, { + chainId: tempoLocalnet.id, + to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', + value: 1n, + feePayer, + }) + + sendTransactionSync(config, { + chainId: mainnet.id, + to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', + value: 1n, + // @ts-expect-error + feePayer: true, + }) + + type Result = SendTransactionSyncParameters + expectTypeOf().not.toMatchTypeOf<{ + feePayer?: true | typeof feePayer | undefined + }>() +}) diff --git a/packages/core/src/actions/sendTransactionSync.ts b/packages/core/src/actions/sendTransactionSync.ts index dff0a37224..9c0d1f06c5 100644 --- a/packages/core/src/actions/sendTransactionSync.ts +++ b/packages/core/src/actions/sendTransactionSync.ts @@ -16,7 +16,7 @@ import type { ChainIdParameter, ConnectorParameter, } from '../types/properties.js' -import type { Compute } from '../types/utils.js' +import type { UnionCompute, UnionLooseOmit } from '../types/utils.js' import { getAction } from '../utils/getAction.js' import { type GetConnectorClientErrorType, @@ -30,15 +30,17 @@ export type SendTransactionSyncParameters< /// chains extends readonly Chain[] = SelectChains, > = { - [key in keyof chains]: Compute< - Omit< + [key in keyof chains]: UnionCompute< + UnionLooseOmit< viem_SendTransactionSyncParameters, 'chain' | 'gas' > & ChainIdParameter & - ConnectorParameter + SendTransactionSyncOverrides > -}[number] & { +}[number] + +type SendTransactionSyncOverrides = ConnectorParameter & { /** Gas provided for transaction execution. */ gas?: TransactionRequest['gas'] | null } diff --git a/packages/core/src/actions/writeContract.test-d.ts b/packages/core/src/actions/writeContract.test-d.ts index 29098787d5..a349e2709c 100644 --- a/packages/core/src/actions/writeContract.test-d.ts +++ b/packages/core/src/actions/writeContract.test-d.ts @@ -1,6 +1,7 @@ import { abi, config } from '@wagmi/test' import { type Address, http, parseAbi } from 'viem' -import { celo, mainnet } from 'viem/chains' +import { privateKeyToAccount } from 'viem/accounts' +import { celo, mainnet, tempoLocalnet } from 'viem/chains' import { expectTypeOf, test } from 'vitest' import { createConfig } from '../createConfig.js' @@ -105,6 +106,56 @@ test('chain formatters', () => { }) }) +test('tempo feePayer', () => { + const feePayer = privateKeyToAccount( + '0x0123456789012345678901234567890123456789012345678901234567890123', + ) + + const config = createConfig({ + chains: [mainnet, tempoLocalnet], + transports: { [mainnet.id]: http(), [tempoLocalnet.id]: http() }, + }) + + writeContract(config, { + chainId: tempoLocalnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + feePayer: true, + }) + + writeContract(config, { + chainId: tempoLocalnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + feePayer, + }) + + writeContract(config, { + chainId: mainnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + // @ts-expect-error + feePayer: true, + }) + + type Result = WriteContractParameters< + typeof abi.erc20, + 'transferFrom', + [Address, Address, bigint], + typeof config, + typeof mainnet.id + > + expectTypeOf().not.toMatchTypeOf<{ + feePayer?: true | typeof feePayer | undefined + }>() +}) + test('overloads', async () => { const abi = parseAbi([ 'function foo() returns (int8)', diff --git a/packages/core/src/actions/writeContractSync.test-d.ts b/packages/core/src/actions/writeContractSync.test-d.ts new file mode 100644 index 0000000000..acf3f7e659 --- /dev/null +++ b/packages/core/src/actions/writeContractSync.test-d.ts @@ -0,0 +1,64 @@ +import { abi } from '@wagmi/test' +import { type Address, http } from 'viem' +import { privateKeyToAccount } from 'viem/accounts' +import { mainnet, tempoLocalnet } from 'viem/chains' +import { expectTypeOf, test } from 'vitest' + +import { createConfig } from '../createConfig.js' +import { + type WriteContractSyncParameters, + writeContractSync, +} from './writeContractSync.js' + +test('tempo feePayer', () => { + const feePayer = privateKeyToAccount( + '0x0123456789012345678901234567890123456789012345678901234567890123', + ) + + const config = createConfig({ + chains: [mainnet, tempoLocalnet], + transports: { [mainnet.id]: http(), [tempoLocalnet.id]: http() }, + }) + + writeContractSync(config, { + chainId: tempoLocalnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + feePayer: true, + }) + + writeContractSync(config, { + chainId: tempoLocalnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + feePayer, + }) + + type Result = WriteContractSyncParameters< + typeof abi.erc20, + 'transferFrom', + [Address, Address, bigint], + typeof config, + typeof mainnet.id + > + ;(() => { + const parameters: Result = { + chainId: mainnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + // @ts-expect-error + feePayer: true, + } + return parameters + })() + + expectTypeOf().not.toMatchTypeOf<{ + feePayer?: true | typeof feePayer | undefined + }>() +}) diff --git a/packages/react/src/hooks/useSendTransaction.test-d.ts b/packages/react/src/hooks/useSendTransaction.test-d.ts index 341bce942c..65fe39fb57 100644 --- a/packages/react/src/hooks/useSendTransaction.test-d.ts +++ b/packages/react/src/hooks/useSendTransaction.test-d.ts @@ -1,5 +1,7 @@ -import type { SendTransactionErrorType } from '@wagmi/core' +import { createConfig, http, type SendTransactionErrorType } from '@wagmi/core' import type { Hash } from 'viem' +import { privateKeyToAccount } from 'viem/accounts' +import { mainnet, tempoLocalnet } from 'viem/chains' import { expectTypeOf, test } from 'vitest' import { useSendTransaction } from './useSendTransaction.js' @@ -79,3 +81,37 @@ test('context', () => { }, ) }) + +test('tempo feePayer', () => { + const feePayer = privateKeyToAccount( + '0x0123456789012345678901234567890123456789012345678901234567890123', + ) + const config = createConfig({ + chains: [mainnet, tempoLocalnet], + transports: { [mainnet.id]: http(), [tempoLocalnet.id]: http() }, + }) + + const sendTransaction = useSendTransaction({ config }) + + sendTransaction.mutate({ + chainId: tempoLocalnet.id, + to: '0x', + value: 1n, + feePayer: true, + }) + + sendTransaction.mutate({ + chainId: tempoLocalnet.id, + to: '0x', + value: 1n, + feePayer, + }) + + sendTransaction.mutate({ + chainId: mainnet.id, + to: '0x', + value: 1n, + // @ts-expect-error + feePayer: true, + }) +}) diff --git a/packages/react/src/hooks/useSendTransactionSync.test-d.ts b/packages/react/src/hooks/useSendTransactionSync.test-d.ts new file mode 100644 index 0000000000..eea57e2e0b --- /dev/null +++ b/packages/react/src/hooks/useSendTransactionSync.test-d.ts @@ -0,0 +1,93 @@ +'use client' + +import { + createConfig, + http, + type SendTransactionSyncErrorType, +} from '@wagmi/core' +import type { TransactionReceipt } from 'viem' +import { privateKeyToAccount } from 'viem/accounts' +import { mainnet, tempoLocalnet } from 'viem/chains' +import { expectTypeOf, test } from 'vitest' + +import { useSendTransactionSync } from './useSendTransactionSync.js' + +const contextValue = { foo: 'bar' } as const + +test('context', () => { + const sendTransactionSync = useSendTransactionSync({ + mutation: { + onMutate(variables) { + expectTypeOf(variables).toMatchTypeOf< + { chainId?: number | undefined } | undefined + >() + return contextValue + }, + onError(error, variables, context) { + expectTypeOf(variables).toMatchTypeOf<{ + chainId?: number | undefined + }>() + expectTypeOf(error).toEqualTypeOf() + expectTypeOf(context).toEqualTypeOf() + }, + onSuccess(data, variables, context) { + expectTypeOf(variables).toMatchTypeOf<{ + chainId?: number | undefined + }>() + expectTypeOf(data).toEqualTypeOf() + expectTypeOf(context).toEqualTypeOf() + }, + onSettled(data, error, variables, context) { + expectTypeOf(data).toEqualTypeOf() + expectTypeOf(error).toEqualTypeOf() + expectTypeOf(variables).toMatchTypeOf<{ + chainId?: number | undefined + }>() + expectTypeOf(context).toEqualTypeOf() + }, + }, + }) + + expectTypeOf(sendTransactionSync.data).toEqualTypeOf< + TransactionReceipt | undefined + >() + expectTypeOf( + sendTransactionSync.error, + ).toEqualTypeOf() + + sendTransactionSync.mutate({ to: '0x' }) +}) + +test('tempo feePayer', () => { + const feePayer = privateKeyToAccount( + '0x0123456789012345678901234567890123456789012345678901234567890123', + ) + const config = createConfig({ + chains: [mainnet, tempoLocalnet], + transports: { [mainnet.id]: http(), [tempoLocalnet.id]: http() }, + }) + + const sendTransactionSync = useSendTransactionSync({ config }) + + sendTransactionSync.mutate({ + chainId: tempoLocalnet.id, + to: '0x', + value: 1n, + feePayer: true, + }) + + sendTransactionSync.mutate({ + chainId: tempoLocalnet.id, + to: '0x', + value: 1n, + feePayer, + }) + + sendTransactionSync.mutate({ + chainId: mainnet.id, + to: '0x', + value: 1n, + // @ts-expect-error + feePayer: true, + }) +}) diff --git a/packages/react/src/hooks/useWriteContract.test-d.ts b/packages/react/src/hooks/useWriteContract.test-d.ts index 8f552974c1..5061f58c70 100644 --- a/packages/react/src/hooks/useWriteContract.test-d.ts +++ b/packages/react/src/hooks/useWriteContract.test-d.ts @@ -2,6 +2,8 @@ import { createConfig, http, type WriteContractErrorType } from '@wagmi/core' import { base } from '@wagmi/core/chains' import { abi } from '@wagmi/test' import type { Abi, Address, Hash } from 'viem' +import { privateKeyToAccount } from 'viem/accounts' +import { mainnet, tempoLocalnet } from 'viem/chains' import { expectTypeOf, test } from 'vitest' import { useSimulateContract } from './useSimulateContract.js' @@ -134,6 +136,46 @@ test('useSimulateContract', () => { if (request) writeContract(request) }) +test('tempo feePayer', () => { + const feePayer = privateKeyToAccount( + '0x0123456789012345678901234567890123456789012345678901234567890123', + ) + const config = createConfig({ + chains: [mainnet, tempoLocalnet], + transports: { [mainnet.id]: http(), [tempoLocalnet.id]: http() }, + }) + + const { writeContract } = useWriteContract({ config }) + + writeContract({ + chainId: tempoLocalnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + feePayer: true, + }) + + writeContract({ + chainId: tempoLocalnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + feePayer, + }) + + writeContract({ + chainId: mainnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + // @ts-expect-error + feePayer: true, + }) +}) + // https://github.com/wevm/wagmi/issues/3981 test('gh#3981', () => { const config = createConfig({ diff --git a/packages/react/src/hooks/useWriteContractSync.test-d.ts b/packages/react/src/hooks/useWriteContractSync.test-d.ts index f85d7b0270..3b24c2a78f 100644 --- a/packages/react/src/hooks/useWriteContractSync.test-d.ts +++ b/packages/react/src/hooks/useWriteContractSync.test-d.ts @@ -1,6 +1,12 @@ -import type { WriteContractSyncErrorType } from '@wagmi/core' +import { + createConfig, + http, + type WriteContractSyncErrorType, +} from '@wagmi/core' import { abi } from '@wagmi/test' import type { Abi, TransactionReceipt } from 'viem' +import { privateKeyToAccount } from 'viem/accounts' +import { mainnet, tempoLocalnet } from 'viem/chains' import { expectTypeOf, test } from 'vitest' import { useWriteContractSync } from './useWriteContractSync.js' @@ -52,3 +58,43 @@ test('context', () => { chainId: 1, }) }) + +test('tempo feePayer', () => { + const feePayer = privateKeyToAccount( + '0x0123456789012345678901234567890123456789012345678901234567890123', + ) + const config = createConfig({ + chains: [mainnet, tempoLocalnet], + transports: { [mainnet.id]: http(), [tempoLocalnet.id]: http() }, + }) + + const writeContractSync = useWriteContractSync({ config }) + + writeContractSync.mutate({ + chainId: tempoLocalnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + feePayer: true, + }) + + writeContractSync.mutate({ + chainId: tempoLocalnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + feePayer, + }) + + writeContractSync.mutate({ + chainId: mainnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + // @ts-expect-error + feePayer: true, + }) +}) diff --git a/packages/vue/src/composables/useSendTransaction.test-d.ts b/packages/vue/src/composables/useSendTransaction.test-d.ts index cd5b9f20fa..c464284f24 100644 --- a/packages/vue/src/composables/useSendTransaction.test-d.ts +++ b/packages/vue/src/composables/useSendTransaction.test-d.ts @@ -1,5 +1,7 @@ -import type { SendTransactionErrorType } from '@wagmi/core' +import { createConfig, http, type SendTransactionErrorType } from '@wagmi/core' import type { Hash } from 'viem' +import { privateKeyToAccount } from 'viem/accounts' +import { mainnet, tempoLocalnet } from 'viem/chains' import { expectTypeOf, test } from 'vitest' import { useSendTransaction } from './useSendTransaction.js' @@ -79,3 +81,37 @@ test('context', () => { }, ) }) + +test('tempo feePayer', () => { + const feePayer = privateKeyToAccount( + '0x0123456789012345678901234567890123456789012345678901234567890123', + ) + const config = createConfig({ + chains: [mainnet, tempoLocalnet], + transports: { [mainnet.id]: http(), [tempoLocalnet.id]: http() }, + }) + + const sendTransaction = useSendTransaction({ config }) + + sendTransaction.mutate({ + chainId: tempoLocalnet.id, + to: '0x', + value: 1n, + feePayer: true, + }) + + sendTransaction.mutate({ + chainId: tempoLocalnet.id, + to: '0x', + value: 1n, + feePayer, + }) + + sendTransaction.mutate({ + chainId: mainnet.id, + to: '0x', + value: 1n, + // @ts-expect-error + feePayer: true, + }) +}) diff --git a/packages/vue/src/composables/useWriteContract.test-d.ts b/packages/vue/src/composables/useWriteContract.test-d.ts index 098af04229..65983bbfff 100644 --- a/packages/vue/src/composables/useWriteContract.test-d.ts +++ b/packages/vue/src/composables/useWriteContract.test-d.ts @@ -1,6 +1,8 @@ -import type { WriteContractErrorType } from '@wagmi/core' +import { createConfig, http, type WriteContractErrorType } from '@wagmi/core' import { abi } from '@wagmi/test' import type { Abi, Address, Hash } from 'viem' +import { privateKeyToAccount } from 'viem/accounts' +import { mainnet, tempoLocalnet } from 'viem/chains' import { expectTypeOf, test } from 'vitest' import { useSimulateContract } from './useSimulateContract.js' @@ -132,3 +134,43 @@ test('useSimulateContract', () => { const request = data?.value?.request if (request) writeContract.mutate(request) }) + +test('tempo feePayer', () => { + const feePayer = privateKeyToAccount( + '0x0123456789012345678901234567890123456789012345678901234567890123', + ) + const config = createConfig({ + chains: [mainnet, tempoLocalnet], + transports: { [mainnet.id]: http(), [tempoLocalnet.id]: http() }, + }) + + const writeContract = useWriteContract({ config }) + + writeContract.mutate({ + chainId: tempoLocalnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + feePayer: true, + }) + + writeContract.mutate({ + chainId: tempoLocalnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + feePayer, + }) + + writeContract.mutate({ + chainId: mainnet.id, + address: '0x', + abi: abi.erc20, + functionName: 'transferFrom', + args: ['0x', '0x', 123n], + // @ts-expect-error + feePayer: true, + }) +})