diff --git a/.changeset/swift-terms-protect.md b/.changeset/swift-terms-protect.md new file mode 100644 index 0000000000..517d05f813 --- /dev/null +++ b/.changeset/swift-terms-protect.md @@ -0,0 +1,8 @@ +--- +"@wagmi/connectors": minor +"wagmi": minor +"@wagmi/core": minor +"@wagmi/vue": minor +--- + +Removed simulation in `writeContract` & `sendTransaction`. diff --git a/packages/connectors/src/coinbaseWallet.ts b/packages/connectors/src/coinbaseWallet.ts index 8793703f8a..50f732d2c9 100644 --- a/packages/connectors/src/coinbaseWallet.ts +++ b/packages/connectors/src/coinbaseWallet.ts @@ -91,7 +91,6 @@ function version4(parameters: Version4Parameters) { id: 'coinbaseWalletSDK', name: 'Coinbase Wallet', rdns: 'com.coinbase.wallet', - supportsSimulation: true, type: coinbaseWallet.type, async connect({ chainId } = {}) { try { @@ -324,7 +323,6 @@ function version3(parameters: Version3Parameters) { return createConnector((config) => ({ id: 'coinbaseWalletSDK', name: 'Coinbase Wallet', - supportsSimulation: true, type: coinbaseWallet.type, async connect({ chainId } = {}) { try { diff --git a/packages/core/src/actions/codegen/createSimulateContract.test-d.ts b/packages/core/src/actions/codegen/createSimulateContract.test-d.ts index 763436bc78..91e5998977 100644 --- a/packages/core/src/actions/codegen/createSimulateContract.test-d.ts +++ b/packages/core/src/actions/codegen/createSimulateContract.test-d.ts @@ -21,7 +21,6 @@ test('default', async () => { expectTypeOf(result).toMatchTypeOf<{ result: boolean request: { - __mode: 'prepared' chainId: 1 abi: readonly [ { @@ -126,7 +125,6 @@ test('functionName', async () => { expectTypeOf(result).toMatchTypeOf<{ result: boolean request: { - __mode: 'prepared' chainId: 1 abi: readonly [ { diff --git a/packages/core/src/actions/codegen/createSimulateContract.test.ts b/packages/core/src/actions/codegen/createSimulateContract.test.ts index af7aa0f976..bd37d13770 100644 --- a/packages/core/src/actions/codegen/createSimulateContract.test.ts +++ b/packages/core/src/actions/codegen/createSimulateContract.test.ts @@ -23,7 +23,6 @@ test('default', async () => { { "chainId": 1, "request": { - "__mode": "prepared", "abi": [ { "inputs": [], @@ -70,7 +69,6 @@ test('multichain', async () => { { "chainId": 456, "request": { - "__mode": "prepared", "abi": [ { "inputs": [], @@ -112,7 +110,6 @@ test('functionName', async () => { { "chainId": 1, "request": { - "__mode": "prepared", "abi": [ { "inputs": [], diff --git a/packages/core/src/actions/codegen/createWriteContract.ts b/packages/core/src/actions/codegen/createWriteContract.ts index d886ad6a30..6c1d891a3f 100644 --- a/packages/core/src/actions/codegen/createWriteContract.ts +++ b/packages/core/src/actions/codegen/createWriteContract.ts @@ -86,7 +86,10 @@ export type CreateWriteContractReturnType< | undefined } : Compute>) & - ConnectorParameter & { __mode?: 'prepared' } + ConnectorParameter & { + /** @deprecated */ + __mode?: 'prepared' + } >, ) => Promise diff --git a/packages/core/src/actions/sendTransaction.ts b/packages/core/src/actions/sendTransaction.ts index 9531ea4f3c..9c8d1d7443 100644 --- a/packages/core/src/actions/sendTransaction.ts +++ b/packages/core/src/actions/sendTransaction.ts @@ -7,10 +7,7 @@ import type { SendTransactionParameters as viem_SendTransactionParameters, SendTransactionReturnType as viem_SendTransactionReturnType, } from 'viem' -import { - estimateGas as viem_estimateGas, - sendTransaction as viem_sendTransaction, -} from 'viem/actions' +import { sendTransaction as viem_sendTransaction } from 'viem/actions' import type { Config } from '../createConfig.js' import type { BaseErrorType, ErrorType } from '../errors/base.js' @@ -21,7 +18,6 @@ import type { } from '../types/properties.js' import type { Compute } from '../types/utils.js' import { getAction } from '../utils/getAction.js' -import { getAccount } from './getAccount.js' import { type GetConnectorClientErrorType, getConnectorClient, @@ -66,7 +62,7 @@ export async function sendTransaction< config: config, parameters: SendTransactionParameters, ): Promise { - const { account, chainId, connector, gas: gas_, ...rest } = parameters + const { account, chainId, connector, ...rest } = parameters let client: Client if (typeof account === 'object' && account?.type === 'local') @@ -78,37 +74,10 @@ export async function sendTransaction< connector, }) - const { connector: activeConnector } = getAccount(config) - - const gas = await (async () => { - // Skip gas estimation if `data` doesn't exist (not a contract interaction). - if (!('data' in parameters) || !parameters.data) return undefined - - // Skip gas estimation if connector supports simulation. - if ((connector ?? activeConnector)?.supportsSimulation) return undefined - - // Skip gas estimation if `null` is provided. - if (gas_ === null) return undefined - - // Run gas estimation if no value is provided. - if (gas_ === undefined) { - const action = getAction(client, viem_estimateGas, 'estimateGas') - return action({ - ...(rest as any), - account, - chain: chainId ? { id: chainId } : null, - }) - } - - // Use provided gas value. - return gas_ - })() - const action = getAction(client, viem_sendTransaction, 'sendTransaction') const hash = await action({ ...(rest as any), ...(account ? { account } : {}), - gas, chain: chainId ? { id: chainId } : null, }) diff --git a/packages/core/src/actions/simulateContract.test-d.ts b/packages/core/src/actions/simulateContract.test-d.ts index 6a485569da..3f893ff8f8 100644 --- a/packages/core/src/actions/simulateContract.test-d.ts +++ b/packages/core/src/actions/simulateContract.test-d.ts @@ -22,7 +22,6 @@ test('default', async () => { expectTypeOf(response).toMatchTypeOf<{ result: boolean request: { - __mode: 'prepared' chainId: 1 abi: readonly [ { diff --git a/packages/core/src/actions/simulateContract.test.ts b/packages/core/src/actions/simulateContract.test.ts index 7857217592..a52cbd5568 100644 --- a/packages/core/src/actions/simulateContract.test.ts +++ b/packages/core/src/actions/simulateContract.test.ts @@ -19,7 +19,6 @@ test('parameters: account', async () => { { "chainId": 1, "request": { - "__mode": "prepared", "abi": [ { "inputs": [], @@ -58,7 +57,6 @@ test('parameters: connector', async () => { { "chainId": 1, "request": { - "__mode": "prepared", "abi": [ { "inputs": [], diff --git a/packages/core/src/actions/simulateContract.ts b/packages/core/src/actions/simulateContract.ts index 6d9713ab18..e5fe5655ff 100644 --- a/packages/core/src/actions/simulateContract.ts +++ b/packages/core/src/actions/simulateContract.ts @@ -96,7 +96,7 @@ export type SimulateContractReturnType< chainId: chains[key]['id'] request: Compute< PartialBy< - { __mode: 'prepared'; chainId: chainId; chain: chains[key] }, + { chainId: chainId; chain: chains[key] }, chainId extends config['chains'][number]['id'] ? never : 'chainId' > > @@ -155,7 +155,7 @@ export async function simulateContract< return { chainId: client.chain.id, result, - request: { __mode: 'prepared', ...request, chainId }, + request: { ...request, chainId }, } as unknown as SimulateContractReturnType< abi, functionName, diff --git a/packages/core/src/actions/writeContract.test-d.ts b/packages/core/src/actions/writeContract.test-d.ts index ce3216ff6d..68009a3773 100644 --- a/packages/core/src/actions/writeContract.test-d.ts +++ b/packages/core/src/actions/writeContract.test-d.ts @@ -28,7 +28,6 @@ test('simulateContract', async () => { }) await writeContract(config, request) await writeContract(config, { - __mode: 'prepared', address: '0x', abi: abi.erc20, functionName: 'transferFrom', diff --git a/packages/core/src/actions/writeContract.ts b/packages/core/src/actions/writeContract.ts index c68deb6e77..5fb6d87104 100644 --- a/packages/core/src/actions/writeContract.ts +++ b/packages/core/src/actions/writeContract.ts @@ -22,15 +22,10 @@ import type { } from '../types/properties.js' import type { Compute, UnionCompute } from '../types/utils.js' import { getAction } from '../utils/getAction.js' -import { getAccount } from './getAccount.js' import { type GetConnectorClientErrorType, getConnectorClient, } from './getConnectorClient.js' -import { - type SimulateContractErrorType, - simulateContract, -} from './simulateContract.js' export type WriteContractParameters< abi extends Abi | readonly unknown[] = Abi, @@ -64,7 +59,10 @@ export type WriteContractParameters< > }[number] & Compute> & - ConnectorParameter & { __mode?: 'prepared' } + ConnectorParameter & { + /** @deprecated */ + __mode?: 'prepared' + } > export type WriteContractReturnType = viem_WriteContractReturnType @@ -72,8 +70,6 @@ export type WriteContractReturnType = viem_WriteContractReturnType export type WriteContractErrorType = // getConnectorClient() | GetConnectorClientErrorType - // simulateContract() - | SimulateContractErrorType // base | BaseErrorType | ErrorType @@ -95,7 +91,7 @@ export async function writeContract< config: config, parameters: WriteContractParameters, ): Promise { - const { account, chainId, connector, __mode, ...rest } = parameters + const { account, chainId, connector, ...request } = parameters let client: Client if (typeof account === 'object' && account?.type === 'local') @@ -107,23 +103,9 @@ export async function writeContract< connector, }) - const { connector: activeConnector } = getAccount(config) - - let request: any - if (__mode === 'prepared' || activeConnector?.supportsSimulation) - request = rest - else { - const { request: simulateRequest } = await simulateContract(config, { - ...rest, - account, - chainId, - } as any) - request = simulateRequest - } - const action = getAction(client, viem_writeContract, 'writeContract') const hash = await action({ - ...request, + ...(request as any), ...(account ? { account } : {}), chain: chainId ? { id: chainId } : null, }) diff --git a/packages/core/src/connectors/createConnector.ts b/packages/core/src/connectors/createConnector.ts index 1724e8d765..b6ae1c2bad 100644 --- a/packages/core/src/connectors/createConnector.ts +++ b/packages/core/src/connectors/createConnector.ts @@ -38,6 +38,7 @@ export type CreateConnectorFn< readonly id: string readonly name: string readonly rdns?: string | readonly string[] | undefined + /** @deprecated */ readonly supportsSimulation?: boolean | undefined readonly type: string diff --git a/packages/core/src/connectors/injected.ts b/packages/core/src/connectors/injected.ts index 7a7c41b51f..c9a9eae033 100644 --- a/packages/core/src/connectors/injected.ts +++ b/packages/core/src/connectors/injected.ts @@ -34,9 +34,6 @@ export type InjectedParameters = { unstable_shimAsyncInject?: boolean | number | undefined } -// Regex of wallets/providers that can accurately simulate contract calls & display contract revert reasons. -const supportsSimulationIdRegex = /(rabby|trustwallet)/ - injected.type = 'injected' as const export function injected(parameters: InjectedParameters = {}) { const { shimDisconnect = true, unstable_shimAsyncInject } = parameters @@ -91,8 +88,9 @@ export function injected(parameters: InjectedParameters = {}) { get name() { return getTarget().name }, + /** @deprecated */ get supportsSimulation() { - return supportsSimulationIdRegex.test(this.id.toLowerCase()) + return true }, type: injected.type, async setup() { diff --git a/packages/react/src/hooks/codegen/createUseSimulateContract.test-d.ts b/packages/react/src/hooks/codegen/createUseSimulateContract.test-d.ts index 6a204737d2..5388e69109 100644 --- a/packages/react/src/hooks/codegen/createUseSimulateContract.test-d.ts +++ b/packages/react/src/hooks/codegen/createUseSimulateContract.test-d.ts @@ -19,7 +19,6 @@ test('default', () => { | { result: boolean request: { - __mode: 'prepared' chainId: 123 abi: readonly [ { @@ -144,7 +143,6 @@ test('functionName', () => { | { result: boolean request: { - __mode: 'prepared' chainId: 123 abi: readonly [ { diff --git a/packages/react/src/hooks/codegen/createUseSimulateContract.test.ts b/packages/react/src/hooks/codegen/createUseSimulateContract.test.ts index 7bc4e4a941..c6e70b90ca 100644 --- a/packages/react/src/hooks/codegen/createUseSimulateContract.test.ts +++ b/packages/react/src/hooks/codegen/createUseSimulateContract.test.ts @@ -28,7 +28,6 @@ test('default', async () => { "data": { "chainId": 1, "request": { - "__mode": "prepared", "abi": [ { "inputs": [], @@ -116,7 +115,6 @@ test('multichain', async () => { "data": { "chainId": 456, "request": { - "__mode": "prepared", "abi": [ { "inputs": [], @@ -197,7 +195,6 @@ test('functionName', async () => { "data": { "chainId": 1, "request": { - "__mode": "prepared", "abi": [ { "inputs": [], diff --git a/packages/react/src/hooks/codegen/createUseWriteContract.ts b/packages/react/src/hooks/codegen/createUseWriteContract.ts index 2680074d23..9e58fd973b 100644 --- a/packages/react/src/hooks/codegen/createUseWriteContract.ts +++ b/packages/react/src/hooks/codegen/createUseWriteContract.ts @@ -290,5 +290,8 @@ type Variables< | undefined } : Compute>) & - ConnectorParameter & { __mode?: 'prepared' } + ConnectorParameter & { + /** @deprecated */ + __mode?: 'prepared' + } > diff --git a/packages/react/src/hooks/useSimulateContract.test-d.ts b/packages/react/src/hooks/useSimulateContract.test-d.ts index 38097fad5c..8159cdfccf 100644 --- a/packages/react/src/hooks/useSimulateContract.test-d.ts +++ b/packages/react/src/hooks/useSimulateContract.test-d.ts @@ -20,7 +20,6 @@ test('default', () => { | { result: boolean request: { - __mode: 'prepared' chainId?: undefined abi: readonly [ { @@ -82,7 +81,6 @@ test('UseSimulateContractReturnType', () => { | { result: boolean request: { - __mode: 'prepared' chainId: number abi: readonly [ { diff --git a/packages/react/src/hooks/useSimulateContract.test.ts b/packages/react/src/hooks/useSimulateContract.test.ts index eb43bde1d9..3c785133c9 100644 --- a/packages/react/src/hooks/useSimulateContract.test.ts +++ b/packages/react/src/hooks/useSimulateContract.test.ts @@ -25,7 +25,6 @@ test('default', async () => { "data": { "chainId": 1, "request": { - "__mode": "prepared", "abi": [ { "inputs": [], diff --git a/packages/react/src/hooks/useWriteContract.test-d.ts b/packages/react/src/hooks/useWriteContract.test-d.ts index d7240de04f..344c11255b 100644 --- a/packages/react/src/hooks/useWriteContract.test-d.ts +++ b/packages/react/src/hooks/useWriteContract.test-d.ts @@ -20,7 +20,6 @@ test('context', () => { mutation: { onMutate(variables) { expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: Abi functionName: string @@ -33,7 +32,6 @@ test('context', () => { expectTypeOf(context).toEqualTypeOf() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: Abi functionName: string @@ -45,7 +43,6 @@ test('context', () => { expectTypeOf(context).toEqualTypeOf() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: Abi functionName: string @@ -58,7 +55,6 @@ test('context', () => { expectTypeOf(context).toEqualTypeOf() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: Abi functionName: string @@ -89,7 +85,6 @@ test('context', () => { expectTypeOf(context).toEqualTypeOf() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: typeof abi.erc20 functionName: 'transferFrom' @@ -105,7 +100,6 @@ test('context', () => { readonly [Address, Address, bigint] >() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: typeof abi.erc20 functionName: 'transferFrom' @@ -118,7 +112,6 @@ test('context', () => { expectTypeOf(context).toEqualTypeOf() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: typeof abi.erc20 functionName: 'transferFrom' diff --git a/packages/vue/src/composables/useSimulateContract.test-d.ts b/packages/vue/src/composables/useSimulateContract.test-d.ts index 0eb2182edb..e8d2451caa 100644 --- a/packages/vue/src/composables/useSimulateContract.test-d.ts +++ b/packages/vue/src/composables/useSimulateContract.test-d.ts @@ -19,7 +19,6 @@ test('default', () => { | { result: boolean request: { - __mode: 'prepared' chainId?: undefined abi: readonly [ { @@ -74,7 +73,6 @@ test('UseSimulateContractReturnType', () => { | { result: boolean request: { - __mode: 'prepared' chainId: number abi: readonly [ { diff --git a/packages/vue/src/composables/useSimulateContract.test.ts b/packages/vue/src/composables/useSimulateContract.test.ts index b93b829b65..1118a51d68 100644 --- a/packages/vue/src/composables/useSimulateContract.test.ts +++ b/packages/vue/src/composables/useSimulateContract.test.ts @@ -24,7 +24,6 @@ test('default', async () => { { "chainId": 1, "request": { - "__mode": "prepared", "abi": [ { "inputs": [], diff --git a/packages/vue/src/composables/useWriteContract.test-d.ts b/packages/vue/src/composables/useWriteContract.test-d.ts index da3e1a5049..33a9b14342 100644 --- a/packages/vue/src/composables/useWriteContract.test-d.ts +++ b/packages/vue/src/composables/useWriteContract.test-d.ts @@ -19,7 +19,6 @@ test('context', () => { mutation: { onMutate(variables) { expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: Abi functionName: string @@ -32,7 +31,6 @@ test('context', () => { expectTypeOf(context).toEqualTypeOf() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: Abi functionName: string @@ -44,7 +42,6 @@ test('context', () => { expectTypeOf(context).toEqualTypeOf() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: Abi functionName: string @@ -57,7 +54,6 @@ test('context', () => { expectTypeOf(context).toEqualTypeOf() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: Abi functionName: string @@ -88,7 +84,6 @@ test('context', () => { expectTypeOf(context).toEqualTypeOf() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: typeof abi.erc20 functionName: 'transferFrom' @@ -104,7 +99,6 @@ test('context', () => { readonly [Address, Address, bigint] >() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: typeof abi.erc20 functionName: 'transferFrom' @@ -117,7 +111,6 @@ test('context', () => { expectTypeOf(context).toEqualTypeOf() expectTypeOf(variables).toMatchTypeOf<{ - __mode?: 'prepared' chainId?: number | undefined abi: typeof abi.erc20 functionName: 'transferFrom' diff --git a/site/dev/creating-connectors.md b/site/dev/creating-connectors.md index 0b98e834cf..c9e82b04b1 100644 --- a/site/dev/creating-connectors.md +++ b/site/dev/creating-connectors.md @@ -55,7 +55,6 @@ The type error tells you what properties are missing from `createConnector`'s re - `id`: The ID for the connector. This should be camel-cased and as short as possible. Example: `fooBarBaz`. - `name`: Human-readable name for the connector. Example: `'Foo Bar Baz'`. - `rdns`: Optional reverse DNS for the connector. This is used to filter out duplicate [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963) injected providers when `createConfig#multiInjectedProviderDiscovery` is enabled. -- `supportsSimulation`: Whether the connector supports contract simulation. This should be disabled if a connector's wallet cannot accurately simulate contract writes or display contract revert messages. Defaults to `false`. #### Methods