viem 2.49.3 → 2.50.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/_cjs/actions/ens/getEnsAddress.js +21 -6
  3. package/_cjs/actions/ens/getEnsAddress.js.map +1 -1
  4. package/_cjs/actions/public/call.js +76 -41
  5. package/_cjs/actions/public/call.js.map +1 -1
  6. package/_cjs/actions/public/getBalance.js +11 -4
  7. package/_cjs/actions/public/getBalance.js.map +1 -1
  8. package/_cjs/actions/public/getCode.js +12 -5
  9. package/_cjs/actions/public/getCode.js.map +1 -1
  10. package/_cjs/actions/public/getProof.js +9 -5
  11. package/_cjs/actions/public/getProof.js.map +1 -1
  12. package/_cjs/actions/public/getStorageAt.js +9 -4
  13. package/_cjs/actions/public/getStorageAt.js.map +1 -1
  14. package/_cjs/actions/public/getTransactionCount.js +10 -7
  15. package/_cjs/actions/public/getTransactionCount.js.map +1 -1
  16. package/_cjs/actions/public/multicall.js +3 -1
  17. package/_cjs/actions/public/multicall.js.map +1 -1
  18. package/_cjs/actions/public/readContract.js.map +1 -1
  19. package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
  20. package/_cjs/actions/wallet/sendTransaction.js +14 -0
  21. package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
  22. package/_cjs/actions/wallet/sendTransactionSync.js +15 -0
  23. package/_cjs/actions/wallet/sendTransactionSync.js.map +1 -1
  24. package/_cjs/chains/definitions/mizuhikiTestnetAwaji.js +29 -0
  25. package/_cjs/chains/definitions/mizuhikiTestnetAwaji.js.map +1 -0
  26. package/_cjs/chains/definitions/morphHolesky.js +1 -1
  27. package/_cjs/chains/definitions/morphHolesky.js.map +1 -1
  28. package/_cjs/chains/definitions/sentrix.js +29 -0
  29. package/_cjs/chains/definitions/sentrix.js.map +1 -0
  30. package/_cjs/chains/definitions/sentrixTestnet.js +30 -0
  31. package/_cjs/chains/definitions/sentrixTestnet.js.map +1 -0
  32. package/_cjs/chains/definitions/sova.js +1 -1
  33. package/_cjs/chains/definitions/sova.js.map +1 -1
  34. package/_cjs/chains/index.js +13 -7
  35. package/_cjs/chains/index.js.map +1 -1
  36. package/_cjs/constants/solidity.js.map +1 -1
  37. package/_cjs/errors/version.js +1 -1
  38. package/_cjs/index.js +5 -3
  39. package/_cjs/index.js.map +1 -1
  40. package/_cjs/tempo/Chain.js +19 -0
  41. package/_cjs/tempo/Chain.js.map +1 -0
  42. package/_cjs/tempo/Decorator.js +1 -0
  43. package/_cjs/tempo/Decorator.js.map +1 -1
  44. package/_cjs/tempo/actions/fee.js +61 -0
  45. package/_cjs/tempo/actions/fee.js.map +1 -1
  46. package/_cjs/tempo/chainConfig.js +16 -6
  47. package/_cjs/tempo/chainConfig.js.map +1 -1
  48. package/_cjs/tempo/chains/index.js +11 -0
  49. package/_cjs/tempo/chains/index.js.map +1 -0
  50. package/_cjs/tempo/errors.js +58 -0
  51. package/_cjs/tempo/errors.js.map +1 -0
  52. package/_cjs/tempo/index.js +17 -1
  53. package/_cjs/tempo/index.js.map +1 -1
  54. package/_cjs/utils/abi/encodeEventTopics.js +4 -2
  55. package/_cjs/utils/abi/encodeEventTopics.js.map +1 -1
  56. package/_cjs/utils/block/formatBlockParameter.js +16 -0
  57. package/_cjs/utils/block/formatBlockParameter.js.map +1 -0
  58. package/_cjs/utils/ccipTunnel.js +65 -0
  59. package/_cjs/utils/ccipTunnel.js.map +1 -0
  60. package/_cjs/utils/index.js +6 -4
  61. package/_cjs/utils/index.js.map +1 -1
  62. package/_cjs/utils/nonceManager.js +7 -3
  63. package/_cjs/utils/nonceManager.js.map +1 -1
  64. package/_cjs/utils/observe.js +7 -1
  65. package/_cjs/utils/observe.js.map +1 -1
  66. package/_cjs/utils/rpc/socket.js +19 -2
  67. package/_cjs/utils/rpc/socket.js.map +1 -1
  68. package/_esm/actions/ens/getEnsAddress.js +21 -6
  69. package/_esm/actions/ens/getEnsAddress.js.map +1 -1
  70. package/_esm/actions/public/call.js +76 -41
  71. package/_esm/actions/public/call.js.map +1 -1
  72. package/_esm/actions/public/getBalance.js +11 -4
  73. package/_esm/actions/public/getBalance.js.map +1 -1
  74. package/_esm/actions/public/getCode.js +12 -5
  75. package/_esm/actions/public/getCode.js.map +1 -1
  76. package/_esm/actions/public/getProof.js +9 -5
  77. package/_esm/actions/public/getProof.js.map +1 -1
  78. package/_esm/actions/public/getStorageAt.js +9 -4
  79. package/_esm/actions/public/getStorageAt.js.map +1 -1
  80. package/_esm/actions/public/getTransactionCount.js +10 -7
  81. package/_esm/actions/public/getTransactionCount.js.map +1 -1
  82. package/_esm/actions/public/multicall.js +3 -1
  83. package/_esm/actions/public/multicall.js.map +1 -1
  84. package/_esm/actions/public/readContract.js.map +1 -1
  85. package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
  86. package/_esm/actions/wallet/sendTransaction.js +14 -0
  87. package/_esm/actions/wallet/sendTransaction.js.map +1 -1
  88. package/_esm/actions/wallet/sendTransactionSync.js +15 -0
  89. package/_esm/actions/wallet/sendTransactionSync.js.map +1 -1
  90. package/_esm/chains/definitions/mizuhikiTestnetAwaji.js +26 -0
  91. package/_esm/chains/definitions/mizuhikiTestnetAwaji.js.map +1 -0
  92. package/_esm/chains/definitions/morphHolesky.js +1 -1
  93. package/_esm/chains/definitions/morphHolesky.js.map +1 -1
  94. package/_esm/chains/definitions/sentrix.js +26 -0
  95. package/_esm/chains/definitions/sentrix.js.map +1 -0
  96. package/_esm/chains/definitions/sentrixTestnet.js +27 -0
  97. package/_esm/chains/definitions/sentrixTestnet.js.map +1 -0
  98. package/_esm/chains/definitions/sova.js +1 -1
  99. package/_esm/chains/definitions/sova.js.map +1 -1
  100. package/_esm/chains/index.js +3 -0
  101. package/_esm/chains/index.js.map +1 -1
  102. package/_esm/constants/solidity.js.map +1 -1
  103. package/_esm/errors/version.js +1 -1
  104. package/_esm/index.js +1 -0
  105. package/_esm/index.js.map +1 -1
  106. package/_esm/tempo/Chain.js +6 -0
  107. package/_esm/tempo/Chain.js.map +1 -0
  108. package/_esm/tempo/Decorator.js +1 -0
  109. package/_esm/tempo/Decorator.js.map +1 -1
  110. package/_esm/tempo/actions/fee.js +83 -0
  111. package/_esm/tempo/actions/fee.js.map +1 -1
  112. package/_esm/tempo/actions/wallet.js +2 -2
  113. package/_esm/tempo/chainConfig.js +18 -8
  114. package/_esm/tempo/chainConfig.js.map +1 -1
  115. package/_esm/tempo/chains/index.js +3 -0
  116. package/_esm/tempo/chains/index.js.map +1 -0
  117. package/_esm/tempo/errors.js +51 -0
  118. package/_esm/tempo/errors.js.map +1 -0
  119. package/_esm/tempo/index.js +2 -0
  120. package/_esm/tempo/index.js.map +1 -1
  121. package/_esm/utils/abi/encodeEventTopics.js +6 -2
  122. package/_esm/utils/abi/encodeEventTopics.js.map +1 -1
  123. package/_esm/utils/block/formatBlockParameter.js +39 -0
  124. package/_esm/utils/block/formatBlockParameter.js.map +1 -0
  125. package/_esm/utils/ccipTunnel.js +62 -0
  126. package/_esm/utils/ccipTunnel.js.map +1 -0
  127. package/_esm/utils/index.js +1 -0
  128. package/_esm/utils/index.js.map +1 -1
  129. package/_esm/utils/nonceManager.js +7 -3
  130. package/_esm/utils/nonceManager.js.map +1 -1
  131. package/_esm/utils/observe.js +7 -1
  132. package/_esm/utils/observe.js.map +1 -1
  133. package/_esm/utils/rpc/socket.js +20 -2
  134. package/_esm/utils/rpc/socket.js.map +1 -1
  135. package/_types/actions/ens/getEnsAddress.d.ts +3 -1
  136. package/_types/actions/ens/getEnsAddress.d.ts.map +1 -1
  137. package/_types/actions/public/call.d.ts +17 -6
  138. package/_types/actions/public/call.d.ts.map +1 -1
  139. package/_types/actions/public/getBalance.d.ts +15 -3
  140. package/_types/actions/public/getBalance.d.ts.map +1 -1
  141. package/_types/actions/public/getCode.d.ts +15 -4
  142. package/_types/actions/public/getCode.d.ts.map +1 -1
  143. package/_types/actions/public/getProof.d.ts +14 -3
  144. package/_types/actions/public/getProof.d.ts.map +1 -1
  145. package/_types/actions/public/getStorageAt.d.ts +15 -4
  146. package/_types/actions/public/getStorageAt.d.ts.map +1 -1
  147. package/_types/actions/public/getTransactionCount.d.ts +15 -3
  148. package/_types/actions/public/getTransactionCount.d.ts.map +1 -1
  149. package/_types/actions/public/multicall.d.ts +1 -1
  150. package/_types/actions/public/multicall.d.ts.map +1 -1
  151. package/_types/actions/public/readContract.d.ts +1 -1
  152. package/_types/actions/public/readContract.d.ts.map +1 -1
  153. package/_types/actions/wallet/prepareTransactionRequest.d.ts +4 -2
  154. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  155. package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
  156. package/_types/actions/wallet/sendTransactionSync.d.ts.map +1 -1
  157. package/_types/chains/definitions/mizuhikiTestnetAwaji.d.ts +46 -0
  158. package/_types/chains/definitions/mizuhikiTestnetAwaji.d.ts.map +1 -0
  159. package/_types/chains/definitions/morphHolesky.d.ts +1 -1
  160. package/_types/chains/definitions/sentrix.d.ts +46 -0
  161. package/_types/chains/definitions/sentrix.d.ts.map +1 -0
  162. package/_types/chains/definitions/sentrixTestnet.d.ts +46 -0
  163. package/_types/chains/definitions/sentrixTestnet.d.ts.map +1 -0
  164. package/_types/chains/definitions/sova.d.ts +1 -1
  165. package/_types/chains/index.d.ts +3 -0
  166. package/_types/chains/index.d.ts.map +1 -1
  167. package/_types/constants/solidity.d.ts +16 -3
  168. package/_types/constants/solidity.d.ts.map +1 -1
  169. package/_types/errors/version.d.ts +1 -1
  170. package/_types/index.d.ts +1 -0
  171. package/_types/index.d.ts.map +1 -1
  172. package/_types/tempo/Chain.d.ts +5 -0
  173. package/_types/tempo/Chain.d.ts.map +1 -0
  174. package/_types/tempo/Decorator.d.ts +23 -0
  175. package/_types/tempo/Decorator.d.ts.map +1 -1
  176. package/_types/tempo/actions/fee.d.ts +38 -0
  177. package/_types/tempo/actions/fee.d.ts.map +1 -1
  178. package/_types/tempo/actions/wallet.d.ts +9 -6
  179. package/_types/tempo/actions/wallet.d.ts.map +1 -1
  180. package/_types/tempo/chainConfig.d.ts.map +1 -1
  181. package/_types/tempo/chains/index.d.ts +2 -0
  182. package/_types/tempo/chains/index.d.ts.map +1 -0
  183. package/_types/tempo/errors.d.ts +36 -0
  184. package/_types/tempo/errors.d.ts.map +1 -0
  185. package/_types/tempo/index.d.ts +2 -0
  186. package/_types/tempo/index.d.ts.map +1 -1
  187. package/_types/types/block.d.ts +3 -4
  188. package/_types/types/block.d.ts.map +1 -1
  189. package/_types/types/eip1193.d.ts +1 -1
  190. package/_types/types/eip1193.d.ts.map +1 -1
  191. package/_types/utils/abi/encodeEventTopics.d.ts +6 -2
  192. package/_types/utils/abi/encodeEventTopics.d.ts.map +1 -1
  193. package/_types/utils/block/formatBlockParameter.d.ts +45 -0
  194. package/_types/utils/block/formatBlockParameter.d.ts.map +1 -0
  195. package/_types/utils/ccipTunnel.d.ts +9 -0
  196. package/_types/utils/ccipTunnel.d.ts.map +1 -0
  197. package/_types/utils/index.d.ts +1 -0
  198. package/_types/utils/index.d.ts.map +1 -1
  199. package/_types/utils/nonceManager.d.ts.map +1 -1
  200. package/_types/utils/observe.d.ts.map +1 -1
  201. package/_types/utils/rpc/socket.d.ts.map +1 -1
  202. package/actions/ens/getEnsAddress.ts +34 -6
  203. package/actions/public/call.ts +125 -51
  204. package/actions/public/getBalance.ts +30 -9
  205. package/actions/public/getCode.ts +35 -11
  206. package/actions/public/getProof.ts +27 -11
  207. package/actions/public/getStorageAt.ts +33 -10
  208. package/actions/public/getTransactionCount.ts +33 -11
  209. package/actions/public/multicall.ts +6 -0
  210. package/actions/public/readContract.ts +2 -0
  211. package/actions/wallet/prepareTransactionRequest.ts +11 -15
  212. package/actions/wallet/sendTransaction.ts +13 -0
  213. package/actions/wallet/sendTransactionSync.ts +16 -0
  214. package/chains/definitions/mizuhikiTestnetAwaji.ts +26 -0
  215. package/chains/definitions/morphHolesky.ts +1 -1
  216. package/chains/definitions/sentrix.ts +26 -0
  217. package/chains/definitions/sentrixTestnet.ts +27 -0
  218. package/chains/definitions/sova.ts +1 -1
  219. package/chains/index.ts +3 -0
  220. package/constants/solidity.ts +4 -4
  221. package/errors/version.ts +1 -1
  222. package/index.ts +4 -0
  223. package/package.json +11 -3
  224. package/tempo/Chain.ts +20 -0
  225. package/tempo/Decorator.ts +27 -0
  226. package/tempo/actions/fee.ts +117 -1
  227. package/tempo/actions/wallet.ts +9 -6
  228. package/tempo/chainConfig.ts +18 -12
  229. package/tempo/chains/index.ts +9 -0
  230. package/tempo/chains/package.json +6 -0
  231. package/tempo/errors.ts +78 -0
  232. package/tempo/index.ts +2 -0
  233. package/types/block.ts +3 -5
  234. package/types/eip1193.ts +1 -1
  235. package/utils/abi/encodeEventTopics.ts +25 -6
  236. package/utils/block/formatBlockParameter.ts +63 -0
  237. package/utils/ccipTunnel.ts +67 -0
  238. package/utils/index.ts +4 -0
  239. package/utils/nonceManager.ts +7 -3
  240. package/utils/observe.ts +7 -4
  241. package/utils/rpc/socket.ts +21 -2
@@ -33,8 +33,11 @@ import {
33
33
  import type { BlockTag } from '../../types/block.js'
34
34
  import type { Chain } from '../../types/chain.js'
35
35
  import type { EIP1193RequestOptions } from '../../types/eip1193.js'
36
- import type { Hex } from '../../types/misc.js'
37
- import type { RpcTransactionRequest } from '../../types/rpc.js'
36
+ import type { Hash, Hex } from '../../types/misc.js'
37
+ import type {
38
+ RpcStateOverride,
39
+ RpcTransactionRequest,
40
+ } from '../../types/rpc.js'
38
41
  import type { StateOverride } from '../../types/stateOverride.js'
39
42
  import type { TransactionRequest } from '../../types/transaction.js'
40
43
  import type { ExactPartial, UnionOmit } from '../../types/utils.js'
@@ -50,15 +53,16 @@ import {
50
53
  type EncodeFunctionDataErrorType,
51
54
  encodeFunctionData,
52
55
  } from '../../utils/abi/encodeFunctionData.js'
56
+ import { isAddressEqual } from '../../utils/address/isAddressEqual.js'
57
+ import {
58
+ type FormatBlockParameterErrorType,
59
+ formatBlockParameter,
60
+ } from '../../utils/block/formatBlockParameter.js'
53
61
  import type { RequestErrorType } from '../../utils/buildRequest.js'
54
62
  import {
55
63
  type GetChainContractAddressErrorType,
56
64
  getChainContractAddress,
57
65
  } from '../../utils/chain/getChainContractAddress.js'
58
- import {
59
- type NumberToHexErrorType,
60
- numberToHex,
61
- } from '../../utils/encoding/toHex.js'
62
66
  import {
63
67
  type GetCallErrorReturnType,
64
68
  getCallError,
@@ -104,17 +108,29 @@ export type CallParameters<
104
108
  stateOverride?: StateOverride | undefined
105
109
  } & (
106
110
  | {
107
- /** The balance of the account at a block number. */
111
+ /** The block number to perform the call against. */
108
112
  blockNumber?: bigint | undefined
109
113
  blockTag?: undefined
114
+ blockHash?: undefined
115
+ requireCanonical?: undefined
110
116
  }
111
117
  | {
112
118
  blockNumber?: undefined
113
119
  /**
114
- * The balance of the account at a block tag.
120
+ * The block tag to perform the call against.
115
121
  * @default 'latest'
116
122
  */
117
123
  blockTag?: BlockTag | undefined
124
+ blockHash?: undefined
125
+ requireCanonical?: undefined
126
+ }
127
+ | {
128
+ blockNumber?: undefined
129
+ blockTag?: undefined
130
+ /** The block hash to perform the call against. */
131
+ blockHash: Hash
132
+ /** Whether or not to throw an error if the block is not in the canonical chain. Only allowed in conjunction with `blockHash`. */
133
+ requireCanonical?: boolean | undefined
118
134
  }
119
135
  )
120
136
  type FormattedCall<chain extends Chain | undefined = Chain | undefined> =
@@ -126,7 +142,7 @@ export type CallErrorType = GetCallErrorReturnType<
126
142
  | ParseAccountErrorType
127
143
  | SerializeStateOverrideErrorType
128
144
  | AssertRequestErrorType
129
- | NumberToHexErrorType
145
+ | FormatBlockParameterErrorType
130
146
  | FormatTransactionRequestErrorType
131
147
  | ScheduleMulticallErrorType
132
148
  | RequestErrorType
@@ -167,8 +183,10 @@ export async function call<chain extends Chain | undefined>(
167
183
  account: account_ = client.account,
168
184
  authorizationList,
169
185
  batch = Boolean(client.batch?.multicall),
186
+ blockHash,
170
187
  blockNumber,
171
188
  blockTag = client.experimental_blockTag ?? 'latest',
189
+ requireCanonical,
172
190
  accessList,
173
191
  blobs,
174
192
  blockOverrides,
@@ -222,9 +240,12 @@ export async function call<chain extends Chain | undefined>(
222
240
  try {
223
241
  assertRequest(args as AssertRequestParameters)
224
242
 
225
- const blockNumberHex =
226
- typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : undefined
227
- const block = blockNumberHex || blockTag
243
+ const block = formatBlockParameter({
244
+ blockHash,
245
+ blockNumber,
246
+ blockTag,
247
+ requireCanonical,
248
+ })
228
249
 
229
250
  const rpcBlockOverrides = blockOverrides
230
251
  ? BlockOverrides.toRpc(blockOverrides)
@@ -258,16 +279,33 @@ export async function call<chain extends Chain | undefined>(
258
279
  if (
259
280
  batch &&
260
281
  shouldPerformMulticall({ request }) &&
261
- !rpcStateOverride &&
262
- !rpcBlockOverrides
282
+ !rpcBlockOverrides &&
283
+ blockHash === undefined
263
284
  ) {
264
285
  try {
265
- return await scheduleMulticall(client, {
266
- ...request,
286
+ const { deployless = false } =
287
+ typeof client.batch?.multicall === 'object'
288
+ ? client.batch.multicall
289
+ : {}
290
+ const multicallAddress = getMulticallAddress(client, {
267
291
  blockNumber,
268
- blockTag,
269
- requestOptions,
270
- } as unknown as ScheduleMulticallParameters<chain>)
292
+ deployless,
293
+ })
294
+
295
+ if (
296
+ !multicallAddress ||
297
+ !hasStateOverrideForAddress(rpcStateOverride, multicallAddress)
298
+ )
299
+ return await scheduleMulticall(client, {
300
+ ...request,
301
+ blockHash,
302
+ blockNumber,
303
+ blockTag,
304
+ multicallAddress,
305
+ requestOptions,
306
+ requireCanonical,
307
+ rpcStateOverride,
308
+ } as unknown as ScheduleMulticallParameters<chain>)
271
309
  } catch (err) {
272
310
  if (
273
311
  !(err instanceof ClientChainNotConfiguredError) &&
@@ -362,17 +400,18 @@ function getRequestOptionsId(
362
400
 
363
401
  type ScheduleMulticallParameters<chain extends Chain | undefined> = Pick<
364
402
  CallParameters<chain>,
365
- 'blockNumber' | 'blockTag'
403
+ 'blockHash' | 'blockNumber' | 'blockTag' | 'requireCanonical'
366
404
  > & {
367
405
  data: Hex
368
- multicallAddress?: Address | undefined
406
+ multicallAddress?: Address | null | undefined
369
407
  requestOptions?: EIP1193RequestOptions | undefined
370
408
  to: Address
409
+ rpcStateOverride?: RpcStateOverride | undefined
371
410
  }
372
411
 
373
412
  type ScheduleMulticallErrorType =
374
413
  | GetChainContractAddressErrorType
375
- | NumberToHexErrorType
414
+ | FormatBlockParameterErrorType
376
415
  | CreateBatchSchedulerErrorType
377
416
  | EncodeFunctionDataErrorType
378
417
  | DecodeFunctionResultErrorType
@@ -389,32 +428,39 @@ async function scheduleMulticall<chain extends Chain | undefined>(
389
428
  wait = 0,
390
429
  } = typeof client.batch?.multicall === 'object' ? client.batch.multicall : {}
391
430
  const {
431
+ blockHash,
392
432
  blockNumber,
393
433
  blockTag = client.experimental_blockTag ?? 'latest',
434
+ requireCanonical,
394
435
  data,
436
+ multicallAddress: multicallAddress_,
395
437
  requestOptions,
438
+ rpcStateOverride,
396
439
  to,
397
440
  } = args
398
441
 
399
- const multicallAddress = (() => {
400
- if (deployless) return null
401
- if (args.multicallAddress) return args.multicallAddress
402
- if (client.chain) {
403
- return getChainContractAddress({
404
- blockNumber,
405
- chain: client.chain,
406
- contract: 'multicall3',
407
- })
408
- }
409
- throw new ClientChainNotConfiguredError()
410
- })()
442
+ const multicallAddress =
443
+ multicallAddress_ !== undefined
444
+ ? multicallAddress_
445
+ : getMulticallAddress(client, {
446
+ blockNumber,
447
+ deployless,
448
+ })
449
+
450
+ const block = formatBlockParameter({
451
+ blockHash,
452
+ blockNumber,
453
+ blockTag,
454
+ requireCanonical,
455
+ })
456
+ const blockId = typeof block === 'string' ? block : JSON.stringify(block)
411
457
 
412
- const blockNumberHex =
413
- typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : undefined
414
- const block = blockNumberHex || blockTag
458
+ const stateOverrideKey = rpcStateOverride
459
+ ? `.${JSON.stringify(rpcStateOverride)}`
460
+ : ''
415
461
 
416
462
  const { schedule } = createBatchScheduler({
417
- id: `${client.uid}.${block}.${getRequestOptionsId(requestOptions)}`,
463
+ id: `${client.uid}.${blockId}.${getRequestOptionsId(requestOptions)}${stateOverrideKey}`,
418
464
  wait,
419
465
  shouldSplitBatch(args) {
420
466
  const size = args.reduce((size, { data }) => size + (data.length - 2), 0)
@@ -438,22 +484,22 @@ async function scheduleMulticall<chain extends Chain | undefined>(
438
484
  functionName: 'aggregate3',
439
485
  })
440
486
 
487
+ const multicallRequest = {
488
+ ...(multicallAddress === null
489
+ ? {
490
+ data: toDeploylessCallViaBytecodeData({
491
+ code: multicall3Bytecode,
492
+ data: calldata,
493
+ }),
494
+ }
495
+ : { to: multicallAddress, data: calldata }),
496
+ }
441
497
  const data = await client.request(
442
498
  {
443
499
  method: 'eth_call',
444
- params: [
445
- {
446
- ...(multicallAddress === null
447
- ? {
448
- data: toDeploylessCallViaBytecodeData({
449
- code: multicall3Bytecode,
450
- data: calldata,
451
- }),
452
- }
453
- : { to: multicallAddress, data: calldata }),
454
- },
455
- block,
456
- ],
500
+ params: rpcStateOverride
501
+ ? [multicallRequest, block, rpcStateOverride]
502
+ : [multicallRequest, block],
457
503
  },
458
504
  requestOptions,
459
505
  )
@@ -474,6 +520,34 @@ async function scheduleMulticall<chain extends Chain | undefined>(
474
520
  return { data: returnData }
475
521
  }
476
522
 
523
+ function getMulticallAddress(
524
+ client: Client<Transport>,
525
+ parameters: {
526
+ blockNumber?: bigint | undefined
527
+ deployless?: boolean | undefined
528
+ },
529
+ ): Address | null {
530
+ const { blockNumber, deployless } = parameters
531
+ if (deployless) return null
532
+ if (client.chain)
533
+ return getChainContractAddress({
534
+ blockNumber,
535
+ chain: client.chain,
536
+ contract: 'multicall3',
537
+ })
538
+ throw new ClientChainNotConfiguredError()
539
+ }
540
+
541
+ function hasStateOverrideForAddress(
542
+ rpcStateOverride: RpcStateOverride | undefined,
543
+ address: Address,
544
+ ) {
545
+ if (!rpcStateOverride) return false
546
+ return Object.keys(rpcStateOverride).some((stateOverrideAddress) =>
547
+ isAddressEqual(stateOverrideAddress as Address, address),
548
+ )
549
+ }
550
+
477
551
  type ToDeploylessCallViaBytecodeDataErrorType =
478
552
  | EncodeDeployDataErrorType
479
553
  | ErrorType
@@ -6,13 +6,14 @@ import { multicall3Abi } from '../../constants/abis.js'
6
6
  import type { ErrorType } from '../../errors/utils.js'
7
7
  import type { BlockTag } from '../../types/block.js'
8
8
  import type { Chain } from '../../types/chain.js'
9
+ import type { Hash } from '../../types/misc.js'
9
10
  import { decodeFunctionResult } from '../../utils/abi/decodeFunctionResult.js'
10
11
  import { encodeFunctionData } from '../../utils/abi/encodeFunctionData.js'
11
- import type { RequestErrorType } from '../../utils/buildRequest.js'
12
12
  import {
13
- type NumberToHexErrorType,
14
- numberToHex,
15
- } from '../../utils/encoding/toHex.js'
13
+ type FormatBlockParameterErrorType,
14
+ formatBlockParameter,
15
+ } from '../../utils/block/formatBlockParameter.js'
16
+ import type { RequestErrorType } from '../../utils/buildRequest.js'
16
17
  import { getAction } from '../../utils/getAction.js'
17
18
  import { type CallParameters, call } from './call.js'
18
19
 
@@ -24,18 +25,30 @@ export type GetBalanceParameters = {
24
25
  /** The balance of the account at a block number. */
25
26
  blockNumber?: bigint | undefined
26
27
  blockTag?: undefined
28
+ blockHash?: undefined
29
+ requireCanonical?: undefined
27
30
  }
28
31
  | {
29
32
  blockNumber?: undefined
30
33
  /** The balance of the account at a block tag. */
31
34
  blockTag?: BlockTag | undefined
35
+ blockHash?: undefined
36
+ requireCanonical?: undefined
37
+ }
38
+ | {
39
+ blockNumber?: undefined
40
+ blockTag?: undefined
41
+ /** The balance of the account at a block specified by block hash. */
42
+ blockHash: Hash
43
+ /** Whether or not to throw an error if the block is not in the canonical chain. Only allowed in conjunction with `blockHash`. */
44
+ requireCanonical?: boolean | undefined
32
45
  }
33
46
  )
34
47
 
35
48
  export type GetBalanceReturnType = bigint
36
49
 
37
50
  export type GetBalanceErrorType =
38
- | NumberToHexErrorType
51
+ | FormatBlockParameterErrorType
39
52
  | RequestErrorType
40
53
  | ErrorType
41
54
 
@@ -78,10 +91,19 @@ export async function getBalance<chain extends Chain | undefined>(
78
91
  client: Client<Transport, chain>,
79
92
  {
80
93
  address,
94
+ blockHash,
81
95
  blockNumber,
82
96
  blockTag = client.experimental_blockTag ?? 'latest',
97
+ requireCanonical,
83
98
  }: GetBalanceParameters,
84
99
  ): Promise<GetBalanceReturnType> {
100
+ const block = formatBlockParameter({
101
+ blockHash,
102
+ blockNumber,
103
+ blockTag,
104
+ requireCanonical,
105
+ })
106
+
85
107
  if (client.batch?.multicall && client.chain?.contracts?.multicall3) {
86
108
  const multicall3Address = client.chain.contracts.multicall3.address
87
109
 
@@ -98,8 +120,10 @@ export async function getBalance<chain extends Chain | undefined>(
98
120
  )({
99
121
  to: multicall3Address,
100
122
  data: calldata,
123
+ blockHash,
101
124
  blockNumber,
102
125
  blockTag,
126
+ requireCanonical,
103
127
  } as unknown as CallParameters<chain>)
104
128
 
105
129
  return decodeFunctionResult({
@@ -110,12 +134,9 @@ export async function getBalance<chain extends Chain | undefined>(
110
134
  })
111
135
  }
112
136
 
113
- const blockNumberHex =
114
- typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : undefined
115
-
116
137
  const balance = await client.request({
117
138
  method: 'eth_getBalance',
118
- params: [address, blockNumberHex || blockTag],
139
+ params: [address, block],
119
140
  })
120
141
  return BigInt(balance)
121
142
  }
@@ -5,12 +5,12 @@ import type { Transport } from '../../clients/transports/createTransport.js'
5
5
  import type { ErrorType } from '../../errors/utils.js'
6
6
  import type { BlockTag } from '../../types/block.js'
7
7
  import type { Chain } from '../../types/chain.js'
8
- import type { Hex } from '../../types/misc.js'
9
- import type { RequestErrorType } from '../../utils/buildRequest.js'
8
+ import type { Hash, Hex } from '../../types/misc.js'
10
9
  import {
11
- type NumberToHexErrorType,
12
- numberToHex,
13
- } from '../../utils/encoding/toHex.js'
10
+ type FormatBlockParameterErrorType,
11
+ formatBlockParameter,
12
+ } from '../../utils/block/formatBlockParameter.js'
13
+ import type { RequestErrorType } from '../../utils/buildRequest.js'
14
14
 
15
15
  export type GetCodeParameters = {
16
16
  address: Address
@@ -18,17 +18,29 @@ export type GetCodeParameters = {
18
18
  | {
19
19
  blockNumber?: undefined
20
20
  blockTag?: BlockTag | undefined
21
+ blockHash?: undefined
22
+ requireCanonical?: undefined
21
23
  }
22
24
  | {
23
25
  blockNumber?: bigint | undefined
24
26
  blockTag?: undefined
27
+ blockHash?: undefined
28
+ requireCanonical?: undefined
29
+ }
30
+ | {
31
+ blockNumber?: undefined
32
+ blockTag?: undefined
33
+ /** The bytecode at a block specified by block hash. */
34
+ blockHash: Hash
35
+ /** Whether or not to throw an error if the block is not in the canonical chain. Only allowed in conjunction with `blockHash`. */
36
+ requireCanonical?: boolean | undefined
25
37
  }
26
38
  )
27
39
 
28
40
  export type GetCodeReturnType = Hex | undefined
29
41
 
30
42
  export type GetCodeErrorType =
31
- | NumberToHexErrorType
43
+ | FormatBlockParameterErrorType
32
44
  | RequestErrorType
33
45
  | ErrorType
34
46
 
@@ -57,16 +69,28 @@ export type GetCodeErrorType =
57
69
  */
58
70
  export async function getCode<chain extends Chain | undefined>(
59
71
  client: Client<Transport, chain>,
60
- { address, blockNumber, blockTag = 'latest' }: GetCodeParameters,
72
+ {
73
+ address,
74
+ blockHash,
75
+ blockNumber,
76
+ blockTag = 'latest',
77
+ requireCanonical,
78
+ }: GetCodeParameters,
61
79
  ): Promise<GetCodeReturnType> {
62
- const blockNumberHex =
63
- blockNumber !== undefined ? numberToHex(blockNumber) : undefined
80
+ const block = formatBlockParameter({
81
+ blockHash,
82
+ blockNumber,
83
+ blockTag,
84
+ requireCanonical,
85
+ })
64
86
  const hex = await client.request(
65
87
  {
66
88
  method: 'eth_getCode',
67
- params: [address, blockNumberHex || blockTag],
89
+ params: [address, block],
90
+ },
91
+ {
92
+ dedupe: typeof blockNumber === 'bigint' || blockHash !== undefined,
68
93
  },
69
- { dedupe: Boolean(blockNumberHex) },
70
94
  )
71
95
  if (hex === '0x') return undefined
72
96
  return hex
@@ -6,11 +6,11 @@ import type { BlockTag } from '../../types/block.js'
6
6
  import type { Chain } from '../../types/chain.js'
7
7
  import type { Hash } from '../../types/misc.js'
8
8
  import type { Proof } from '../../types/proof.js'
9
- import type { RequestErrorType } from '../../utils/buildRequest.js'
10
9
  import {
11
- type NumberToHexErrorType,
12
- numberToHex,
13
- } from '../../utils/encoding/toHex.js'
10
+ type FormatBlockParameterErrorType,
11
+ formatBlockParameter,
12
+ } from '../../utils/block/formatBlockParameter.js'
13
+ import type { RequestErrorType } from '../../utils/buildRequest.js'
14
14
  import {
15
15
  type FormatProofErrorType,
16
16
  formatProof,
@@ -26,6 +26,8 @@ export type GetProofParameters = {
26
26
  /** The block number. */
27
27
  blockNumber?: bigint | undefined
28
28
  blockTag?: undefined
29
+ blockHash?: undefined
30
+ requireCanonical?: undefined
29
31
  }
30
32
  | {
31
33
  blockNumber?: undefined
@@ -34,13 +36,23 @@ export type GetProofParameters = {
34
36
  * @default 'latest'
35
37
  */
36
38
  blockTag?: BlockTag | undefined
39
+ blockHash?: undefined
40
+ requireCanonical?: undefined
41
+ }
42
+ | {
43
+ blockNumber?: undefined
44
+ blockTag?: undefined
45
+ /** The proof at a block specified by block hash. */
46
+ blockHash: Hash
47
+ /** Whether or not to throw an error if the block is not in the canonical chain. Only allowed in conjunction with `blockHash`. */
48
+ requireCanonical?: boolean | undefined
37
49
  }
38
50
  )
39
51
 
40
52
  export type GetProofReturnType = Proof
41
53
 
42
54
  export type GetProofErrorType =
43
- | NumberToHexErrorType
55
+ | FormatBlockParameterErrorType
44
56
  | FormatProofErrorType
45
57
  | RequestErrorType
46
58
  | ErrorType
@@ -74,19 +86,23 @@ export async function getProof<chain extends Chain | undefined>(
74
86
  client: Client<Transport, chain>,
75
87
  {
76
88
  address,
89
+ blockHash,
77
90
  blockNumber,
78
- blockTag: blockTag_,
91
+ blockTag = 'latest',
92
+ requireCanonical,
79
93
  storageKeys,
80
94
  }: GetProofParameters,
81
95
  ): Promise<GetProofReturnType> {
82
- const blockTag = blockTag_ ?? 'latest'
83
-
84
- const blockNumberHex =
85
- blockNumber !== undefined ? numberToHex(blockNumber) : undefined
96
+ const block = formatBlockParameter({
97
+ blockHash,
98
+ blockNumber,
99
+ blockTag,
100
+ requireCanonical,
101
+ })
86
102
 
87
103
  const proof = await client.request({
88
104
  method: 'eth_getProof',
89
- params: [address, storageKeys, blockNumberHex || blockTag],
105
+ params: [address, storageKeys, block],
90
106
  })
91
107
 
92
108
  return formatProof(proof)
@@ -5,12 +5,12 @@ import type { Transport } from '../../clients/transports/createTransport.js'
5
5
  import type { ErrorType } from '../../errors/utils.js'
6
6
  import type { BlockTag } from '../../types/block.js'
7
7
  import type { Chain } from '../../types/chain.js'
8
- import type { Hex } from '../../types/misc.js'
9
- import type { RequestErrorType } from '../../utils/buildRequest.js'
8
+ import type { Hash, Hex } from '../../types/misc.js'
10
9
  import {
11
- type NumberToHexErrorType,
12
- numberToHex,
13
- } from '../../utils/encoding/toHex.js'
10
+ type FormatBlockParameterErrorType,
11
+ formatBlockParameter,
12
+ } from '../../utils/block/formatBlockParameter.js'
13
+ import type { RequestErrorType } from '../../utils/buildRequest.js'
14
14
 
15
15
  export type GetStorageAtParameters = {
16
16
  address: Address
@@ -19,17 +19,29 @@ export type GetStorageAtParameters = {
19
19
  | {
20
20
  blockNumber?: undefined
21
21
  blockTag?: BlockTag | undefined
22
+ blockHash?: undefined
23
+ requireCanonical?: undefined
22
24
  }
23
25
  | {
24
26
  blockNumber?: bigint | undefined
25
27
  blockTag?: undefined
28
+ blockHash?: undefined
29
+ requireCanonical?: undefined
30
+ }
31
+ | {
32
+ blockNumber?: undefined
33
+ blockTag?: undefined
34
+ /** The storage value at a block specified by block hash. */
35
+ blockHash: Hash
36
+ /** Whether or not to throw an error if the block is not in the canonical chain. Only allowed in conjunction with `blockHash`. */
37
+ requireCanonical?: boolean | undefined
26
38
  }
27
39
  )
28
40
 
29
41
  export type GetStorageAtReturnType = Hex | undefined
30
42
 
31
43
  export type GetStorageAtErrorType =
32
- | NumberToHexErrorType
44
+ | FormatBlockParameterErrorType
33
45
  | RequestErrorType
34
46
  | ErrorType
35
47
 
@@ -59,13 +71,24 @@ export type GetStorageAtErrorType =
59
71
  */
60
72
  export async function getStorageAt<chain extends Chain | undefined>(
61
73
  client: Client<Transport, chain>,
62
- { address, blockNumber, blockTag = 'latest', slot }: GetStorageAtParameters,
74
+ {
75
+ address,
76
+ blockHash,
77
+ blockNumber,
78
+ blockTag = 'latest',
79
+ requireCanonical,
80
+ slot,
81
+ }: GetStorageAtParameters,
63
82
  ): Promise<GetStorageAtReturnType> {
64
- const blockNumberHex =
65
- blockNumber !== undefined ? numberToHex(blockNumber) : undefined
83
+ const block = formatBlockParameter({
84
+ blockHash,
85
+ blockNumber,
86
+ blockTag,
87
+ requireCanonical,
88
+ })
66
89
  const data = await client.request({
67
90
  method: 'eth_getStorageAt',
68
- params: [address, slot, blockNumberHex || blockTag],
91
+ params: [address, slot, block],
69
92
  })
70
93
  return data
71
94
  }