diff --git a/.changeset/poor-nails-appear.md b/.changeset/poor-nails-appear.md new file mode 100644 index 0000000000..9ee7e6acc7 --- /dev/null +++ b/.changeset/poor-nails-appear.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/common": patch +--- + +`writeContract` and `sendTransaction` actions now use `pending` block tag when estimating gas. This aligns with previous behavior before changes in the last version. diff --git a/packages/common/src/sendTransaction.ts b/packages/common/src/sendTransaction.ts index 45d526c9b5..6e2775367e 100644 --- a/packages/common/src/sendTransaction.ts +++ b/packages/common/src/sendTransaction.ts @@ -6,6 +6,7 @@ import { Transport, SendTransactionReturnType, PublicClient, + SendTransactionRequest, } from "viem"; import { sendTransaction as viem_sendTransaction } from "viem/actions"; import pRetry from "p-retry"; @@ -38,10 +39,11 @@ export type SendTransactionExtraOptions = { export async function sendTransaction< chain extends Chain | undefined, account extends Account | undefined, - chainOverride extends Chain | undefined, + const request extends SendTransactionRequest, + chainOverride extends Chain | undefined = undefined, >( client: Client, - request: SendTransactionParameters, + request: SendTransactionParameters, opts: SendTransactionExtraOptions = {}, ): Promise { const rawAccount = request.account ?? client.account; @@ -52,10 +54,11 @@ export async function sendTransaction< const account = parseAccount(rawAccount); const chain = client.chain; + const blockTag = "pending"; const nonceManager = await getNonceManager({ client: opts.publicClient ?? client, address: account.address, - blockTag: "pending", + blockTag, queueConcurrency: opts.queueConcurrency, }); @@ -70,13 +73,14 @@ export async function sendTransaction< pRetry( async () => { const nonce = nonceManager.nextNonce(); - const params: SendTransactionParameters = { + const params = { + blockTag, ...request, nonce, ...feeRef.fees, - }; + } as const satisfies SendTransactionParameters; debug("sending tx to", request.to, "with nonce", nonce); - return await getAction(client, viem_sendTransaction, "sendTransaction")(params); + return await getAction(client, viem_sendTransaction, "sendTransaction")(params as never); }, { retries: 3, diff --git a/packages/common/src/writeContract.ts b/packages/common/src/writeContract.ts index 5cd0ed19e9..b23ab4f1dd 100644 --- a/packages/common/src/writeContract.ts +++ b/packages/common/src/writeContract.ts @@ -41,7 +41,7 @@ export type WriteContractExtraOptions = { export async function writeContract< chain extends Chain | undefined, account extends Account | undefined, - abi extends Abi | readonly unknown[], + const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName, args extends ContractFunctionArgs, chainOverride extends Chain | undefined, @@ -58,10 +58,11 @@ export async function writeContract< const account = parseAccount(rawAccount); const chain = client.chain; + const blockTag = "pending"; const nonceManager = await getNonceManager({ client: opts.publicClient ?? client, address: account.address, - blockTag: "pending", + blockTag, queueConcurrency: opts.queueConcurrency, }); @@ -76,13 +77,14 @@ export async function writeContract< pRetry( async () => { const nonce = nonceManager.nextNonce(); - const params: WriteContractParameters = { + const params = { + blockTag, ...request, nonce, ...feeRef.fees, - }; + } as const satisfies WriteContractParameters; debug("calling", params.functionName, "at", params.address, "with nonce", nonce); - return await getAction(client, viem_writeContract, "writeContract")({ ...params }); + return await getAction(client, viem_writeContract, "writeContract")(params as never); }, { retries: 3,