diff --git a/src/actions/public/call.test.ts b/src/actions/public/call.test.ts index 35c971017e..d11d0708ee 100644 --- a/src/actions/public/call.test.ts +++ b/src/actions/public/call.test.ts @@ -586,6 +586,32 @@ describe('errors', () => { `) }) }) + + test('pass code and factory', async () => { + await expect( + call(client, { + code: wagmiContractConfig.bytecode, + factory: wagmiContractConfig.address, + }), + ).rejects.toThrowErrorMatchingInlineSnapshot(` + [ViemError: Cannot provide both \`code\` & \`factory\`/\`factoryData\` as parameters. + + Version: viem@x.y.z] + `) + }) + + test('pass code and to', async () => { + await expect( + call(client, { + code: wagmiContractConfig.bytecode, + to: '0x0000000000000000000000000000000000000000', + }), + ).rejects.toThrowErrorMatchingInlineSnapshot(` + [ViemError: Cannot provide both \`code\` & \`to\` as parameters. + + Version: viem@x.y.z] + `) + }) }) describe('batch call', () => { diff --git a/src/actions/public/call.ts b/src/actions/public/call.ts index 77151500f7..905037951e 100644 --- a/src/actions/public/call.ts +++ b/src/actions/public/call.ts @@ -176,6 +176,13 @@ export async function call( } = args const account = account_ ? parseAccount(account_) : undefined + if (code && (factory || factoryData)) + throw new BaseError( + 'Cannot provide both `code` & `factory`/`factoryData` as parameters.', + ) + if (code && to) + throw new BaseError('Cannot provide both `code` & `to` as parameters.') + // Check if the call is deployless via bytecode. const deploylessCallViaBytecode = code && data_ // Check if the call is deployless via a factory.