Skip to content

Commit 149c789

Browse files
committed
fix: propagate account downstream
1 parent 1e8aff6 commit 149c789

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

src/actions/public/estimateGas.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { encodeFunctionData } from '../../utils/index.js'
1313
import { parseEther } from '../../utils/unit/parseEther.js'
1414
import { parseGwei } from '../../utils/unit/parseGwei.js'
1515
import { reset } from '../test/reset.js'
16+
import * as prepareTransactionRequestModule from '../wallet/prepareTransactionRequest.js'
1617
import { signAuthorization } from '../wallet/signAuthorization.js'
1718
import { estimateGas } from './estimateGas.js'
1819
import * as getBlock from './getBlock.js'
@@ -190,6 +191,26 @@ test('args: override', async () => {
190191
).toMatchInlineSnapshot('51594n')
191192
})
192193

194+
test('args: prepare', async () => {
195+
const prepareTransactionRequestSpy = vi.spyOn(
196+
prepareTransactionRequestModule,
197+
'prepareTransactionRequest',
198+
)
199+
200+
expect(
201+
await estimateGas(client, {
202+
account: accounts[0].address,
203+
to: accounts[1].address,
204+
value: parseEther('1'),
205+
prepare: false,
206+
}),
207+
).toMatchInlineSnapshot('21000n')
208+
209+
expect(prepareTransactionRequestSpy).not.toHaveBeenCalled()
210+
211+
vi.restoreAllMocks()
212+
})
213+
193214
test('error: cannot infer `to` from `authorizationList`', async () => {
194215
await expect(() =>
195216
estimateGas(client, {

src/actions/public/estimateGas.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ import {
3838
} from '../../utils/transaction/assertRequest.js'
3939
import {
4040
type PrepareTransactionRequestParameters,
41+
type PrepareTransactionRequestParameterType,
4142
prepareTransactionRequest,
4243
} from '../wallet/prepareTransactionRequest.js'
4344

4445
export type EstimateGasParameters<
4546
chain extends Chain | undefined = Chain | undefined,
4647
> = UnionOmit<FormattedEstimateGas<chain>, 'from'> & {
4748
account?: Account | Address | undefined
49+
prepare?:
50+
| boolean
51+
| readonly PrepareTransactionRequestParameterType[]
52+
| undefined
4853
stateOverride?: StateOverride | undefined
4954
} & (
5055
| {
@@ -106,7 +111,7 @@ export async function estimateGas<
106111
client: Client<Transport, chain, account>,
107112
args: EstimateGasParameters<chain>,
108113
): Promise<EstimateGasReturnType> {
109-
const { account: account_ = client.account } = args
114+
const { account: account_ = client.account, prepare = true } = args
110115
const account = account_ ? parseAccount(account_) : undefined
111116

112117
try {
@@ -127,13 +132,16 @@ export async function estimateGas<
127132
value,
128133
stateOverride,
129134
...rest
130-
} = (await prepareTransactionRequest(client, {
131-
...args,
132-
parameters:
133-
// Some RPC Providers do not compute versioned hashes from blobs. We will need
134-
// to compute them.
135-
account?.type === 'local' ? undefined : ['blobVersionedHashes'],
136-
} as PrepareTransactionRequestParameters)) as EstimateGasParameters
135+
} = prepare
136+
? ((await prepareTransactionRequest(client, {
137+
...args,
138+
parameters:
139+
prepare ??
140+
// Some RPC Providers do not compute versioned hashes from blobs. We will need
141+
// to compute them.
142+
(account?.type === 'local' ? undefined : ['blobVersionedHashes']),
143+
} as PrepareTransactionRequestParameters)) as EstimateGasParameters)
144+
: args
137145

138146
const blockNumberHex =
139147
typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : undefined

src/actions/wallet/prepareTransactionRequest.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,8 @@ export async function prepareTransactionRequest<
421421
'estimateGas',
422422
)({
423423
...request,
424-
account: account
425-
? { address: account.address, type: 'json-rpc' }
426-
: account,
424+
account,
425+
prepare: account?.type === 'local' ? [] : ['blobVersionedHashes'],
427426
} as EstimateGasParameters)
428427

429428
assertRequest(request as AssertRequestParameters)

0 commit comments

Comments
 (0)