viem 2.21.59 → 2.22.0

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 (59) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/_cjs/actions/index.js +6 -2
  3. package/_cjs/actions/index.js.map +1 -1
  4. package/_cjs/actions/public/createAccessList.js +49 -0
  5. package/_cjs/actions/public/createAccessList.js.map +1 -0
  6. package/_cjs/actions/public/simulate.js +112 -0
  7. package/_cjs/actions/public/simulate.js.map +1 -0
  8. package/_cjs/chains/definitions/mainnet.js +1 -1
  9. package/_cjs/chains/definitions/mainnet.js.map +1 -1
  10. package/_cjs/clients/decorators/public.js +4 -0
  11. package/_cjs/clients/decorators/public.js.map +1 -1
  12. package/_cjs/errors/version.js +1 -1
  13. package/_cjs/errors/version.js.map +1 -1
  14. package/_cjs/index.js.map +1 -1
  15. package/_cjs/types/eip1193.js.map +1 -1
  16. package/_esm/actions/index.js +2 -0
  17. package/_esm/actions/index.js.map +1 -1
  18. package/_esm/actions/public/createAccessList.js +72 -0
  19. package/_esm/actions/public/createAccessList.js.map +1 -0
  20. package/_esm/actions/public/simulate.js +152 -0
  21. package/_esm/actions/public/simulate.js.map +1 -0
  22. package/_esm/chains/definitions/mainnet.js +1 -1
  23. package/_esm/chains/definitions/mainnet.js.map +1 -1
  24. package/_esm/clients/decorators/public.js +4 -0
  25. package/_esm/clients/decorators/public.js.map +1 -1
  26. package/_esm/errors/version.js +1 -1
  27. package/_esm/errors/version.js.map +1 -1
  28. package/_esm/index.js.map +1 -1
  29. package/_esm/types/eip1193.js.map +1 -1
  30. package/_types/actions/index.d.ts +2 -0
  31. package/_types/actions/index.d.ts.map +1 -1
  32. package/_types/actions/public/createAccessList.d.ts +61 -0
  33. package/_types/actions/public/createAccessList.d.ts.map +1 -0
  34. package/_types/actions/public/simulate.d.ts +114 -0
  35. package/_types/actions/public/simulate.d.ts.map +1 -0
  36. package/_types/chains/definitions/mainnet.d.ts +1 -1
  37. package/_types/clients/decorators/public.d.ts +69 -0
  38. package/_types/clients/decorators/public.d.ts.map +1 -1
  39. package/_types/errors/version.d.ts +1 -1
  40. package/_types/errors/version.d.ts.map +1 -1
  41. package/_types/index.d.ts +1 -0
  42. package/_types/index.d.ts.map +1 -1
  43. package/_types/types/calls.d.ts +9 -4
  44. package/_types/types/calls.d.ts.map +1 -1
  45. package/_types/types/eip1193.d.ts +55 -0
  46. package/_types/types/eip1193.d.ts.map +1 -1
  47. package/_types/types/multicall.d.ts +9 -7
  48. package/_types/types/multicall.d.ts.map +1 -1
  49. package/actions/index.ts +12 -0
  50. package/actions/public/createAccessList.ts +159 -0
  51. package/actions/public/simulate.ts +290 -0
  52. package/chains/definitions/mainnet.ts +1 -1
  53. package/clients/decorators/public.ts +83 -0
  54. package/errors/version.ts +1 -1
  55. package/index.ts +4 -0
  56. package/package.json +2 -2
  57. package/types/calls.ts +20 -11
  58. package/types/eip1193.ts +59 -0
  59. package/types/multicall.ts +29 -10
@@ -1 +1 @@
1
- {"version":3,"file":"multicall.d.ts","sourceRoot":"","sources":["../../types/multicall.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC3B,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAExD,MAAM,MAAM,kBAAkB,CAC5B,SAAS,SAAS,SAAS,OAAO,EAAE,EACpC,OAAO,SAAS;IACd,UAAU,EAAE,kBAAkB,CAAA;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACjC,GAAG;IAAE,UAAU,EAAE,kBAAkB,CAAA;CAAE,EAEtC,MAAM,SAAS,SAA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AAU,EAAE,YAAY,CAAC,GAC3D,0BAA0B,CAAC,GAAG,EAAE,UAAU,CAAC,GAC7C,0BAA0B,CAAA"}
package/actions/index.ts CHANGED
@@ -46,6 +46,12 @@ export {
46
46
  type CallReturnType,
47
47
  call,
48
48
  } from './public/call.js'
49
+ export {
50
+ type CreateAccessListErrorType,
51
+ type CreateAccessListParameters,
52
+ type CreateAccessListReturnType,
53
+ createAccessList,
54
+ } from './public/createAccessList.js'
49
55
  export {
50
56
  type CreateBlockFilterErrorType,
51
57
  type CreateBlockFilterReturnType,
@@ -243,6 +249,12 @@ export {
243
249
  type MulticallReturnType,
244
250
  multicall,
245
251
  } from './public/multicall.js'
252
+ export {
253
+ type SimulateErrorType,
254
+ type SimulateParameters,
255
+ type SimulateReturnType,
256
+ simulate,
257
+ } from './public/simulate.js'
246
258
  export {
247
259
  type OnBlock,
248
260
  type OnBlockParameter,
@@ -0,0 +1,159 @@
1
+ import type { Address } from 'abitype'
2
+
3
+ import type { Account } from '../../accounts/types.js'
4
+ import {
5
+ type ParseAccountErrorType,
6
+ parseAccount,
7
+ } from '../../accounts/utils/parseAccount.js'
8
+ import type { Client } from '../../clients/createClient.js'
9
+ import type { Transport } from '../../clients/transports/createTransport.js'
10
+ import type { ErrorType } from '../../errors/utils.js'
11
+ import type { BlockTag } from '../../types/block.js'
12
+ import type { Chain } from '../../types/chain.js'
13
+ import type { RpcTransactionRequest } from '../../types/rpc.js'
14
+ import type { AccessList, TransactionRequest } from '../../types/transaction.js'
15
+ import type { ExactPartial, Prettify, UnionOmit } from '../../types/utils.js'
16
+ import type { RequestErrorType } from '../../utils/buildRequest.js'
17
+ import {
18
+ type NumberToHexErrorType,
19
+ numberToHex,
20
+ } from '../../utils/encoding/toHex.js'
21
+ import {
22
+ type GetCallErrorReturnType,
23
+ getCallError,
24
+ } from '../../utils/errors/getCallError.js'
25
+ import { extract } from '../../utils/formatters/extract.js'
26
+ import {
27
+ type FormatTransactionRequestErrorType,
28
+ type FormattedTransactionRequest,
29
+ formatTransactionRequest,
30
+ } from '../../utils/formatters/transactionRequest.js'
31
+ import { assertRequest } from '../../utils/transaction/assertRequest.js'
32
+ import type {
33
+ AssertRequestErrorType,
34
+ AssertRequestParameters,
35
+ } from '../../utils/transaction/assertRequest.js'
36
+
37
+ export type CreateAccessListParameters<
38
+ chain extends Chain | undefined = Chain | undefined,
39
+ > = UnionOmit<
40
+ FormattedTransactionRequest<chain>,
41
+ 'from' | 'nonce' | 'accessList'
42
+ > & {
43
+ /** Account attached to the call (msg.sender). */
44
+ account?: Account | Address | undefined
45
+ } & (
46
+ | {
47
+ /** The balance of the account at a block number. */
48
+ blockNumber?: bigint | undefined
49
+ blockTag?: undefined
50
+ }
51
+ | {
52
+ blockNumber?: undefined
53
+ /**
54
+ * The balance of the account at a block tag.
55
+ * @default 'latest'
56
+ */
57
+ blockTag?: BlockTag | undefined
58
+ }
59
+ )
60
+
61
+ export type CreateAccessListReturnType = Prettify<{
62
+ accessList: AccessList
63
+ gasUsed: bigint
64
+ }>
65
+
66
+ export type CreateAccessListErrorType = GetCallErrorReturnType<
67
+ | ParseAccountErrorType
68
+ | AssertRequestErrorType
69
+ | NumberToHexErrorType
70
+ | FormatTransactionRequestErrorType
71
+ | RequestErrorType
72
+ >
73
+
74
+ /**
75
+ * Creates an EIP-2930 access list.
76
+ *
77
+ * - Docs: https://viem.sh/docs/actions/public/createAccessList
78
+ * - JSON-RPC Methods: `eth_createAccessList`
79
+ *
80
+ * @param client - Client to use
81
+ * @param parameters - {@link CreateAccessListParameters}
82
+ * @returns The access list. {@link CreateAccessListReturnType}
83
+ *
84
+ * @example
85
+ * import { createPublicClient, http } from 'viem'
86
+ * import { mainnet } from 'viem/chains'
87
+ * import { createAccessList } from 'viem/public'
88
+ *
89
+ * const client = createPublicClient({
90
+ * chain: mainnet,
91
+ * transport: http(),
92
+ * })
93
+ * const data = await createAccessList(client, {
94
+ * account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
95
+ * data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
96
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
97
+ * })
98
+ */
99
+ export async function createAccessList<chain extends Chain | undefined>(
100
+ client: Client<Transport, chain>,
101
+ args: CreateAccessListParameters<chain>,
102
+ ): Promise<CreateAccessListReturnType> {
103
+ const {
104
+ account: account_ = client.account,
105
+ blockNumber,
106
+ blockTag = 'latest',
107
+ blobs,
108
+ data,
109
+ gas,
110
+ gasPrice,
111
+ maxFeePerBlobGas,
112
+ maxFeePerGas,
113
+ maxPriorityFeePerGas,
114
+ to,
115
+ value,
116
+ ...rest
117
+ } = args
118
+ const account = account_ ? parseAccount(account_) : undefined
119
+
120
+ try {
121
+ assertRequest(args as AssertRequestParameters)
122
+
123
+ const blockNumberHex = blockNumber ? numberToHex(blockNumber) : undefined
124
+ const block = blockNumberHex || blockTag
125
+
126
+ const chainFormat = client.chain?.formatters?.transactionRequest?.format
127
+ const format = chainFormat || formatTransactionRequest
128
+
129
+ const request = format({
130
+ // Pick out extra data that might exist on the chain's transaction request type.
131
+ ...extract(rest, { format: chainFormat }),
132
+ from: account?.address,
133
+ blobs,
134
+ data,
135
+ gas,
136
+ gasPrice,
137
+ maxFeePerBlobGas,
138
+ maxFeePerGas,
139
+ maxPriorityFeePerGas,
140
+ to,
141
+ value,
142
+ } as TransactionRequest) as TransactionRequest
143
+
144
+ const response = await client.request({
145
+ method: 'eth_createAccessList',
146
+ params: [request as ExactPartial<RpcTransactionRequest>, block],
147
+ })
148
+ return {
149
+ accessList: response.accessList,
150
+ gasUsed: BigInt(response.gasUsed),
151
+ }
152
+ } catch (err) {
153
+ throw getCallError(err as ErrorType, {
154
+ ...args,
155
+ account,
156
+ chain: client.chain,
157
+ })
158
+ }
159
+ }
@@ -0,0 +1,290 @@
1
+ import type { Abi, AbiStateMutability, Address, Narrow } from 'abitype'
2
+ import * as BlockOverrides from 'ox/BlockOverrides'
3
+
4
+ import {
5
+ type ParseAccountErrorType,
6
+ parseAccount,
7
+ } from '../../accounts/utils/parseAccount.js'
8
+ import type { Client } from '../../clients/createClient.js'
9
+ import type { Transport } from '../../clients/transports/createTransport.js'
10
+ import { AbiDecodingZeroDataError } from '../../errors/abi.js'
11
+ import type { BaseError } from '../../errors/base.js'
12
+ import { RawContractError } from '../../errors/contract.js'
13
+ import { UnknownNodeError } from '../../errors/node.js'
14
+ import type { ErrorType } from '../../errors/utils.js'
15
+ import type { Account } from '../../types/account.js'
16
+ import type { Block, BlockTag } from '../../types/block.js'
17
+ import type { Call, Calls } from '../../types/calls.js'
18
+ import type { Chain } from '../../types/chain.js'
19
+ import type { Log } from '../../types/log.js'
20
+ import type { Hex } from '../../types/misc.js'
21
+ import type { MulticallResults } from '../../types/multicall.js'
22
+ import type { StateOverride } from '../../types/stateOverride.js'
23
+ import type { TransactionRequest } from '../../types/transaction.js'
24
+ import type { ExactPartial, UnionOmit } from '../../types/utils.js'
25
+ import {
26
+ type DecodeFunctionResultErrorType,
27
+ decodeFunctionResult,
28
+ } from '../../utils/abi/decodeFunctionResult.js'
29
+ import {
30
+ type EncodeFunctionDataErrorType,
31
+ encodeFunctionData,
32
+ } from '../../utils/abi/encodeFunctionData.js'
33
+ import {
34
+ type NumberToHexErrorType,
35
+ numberToHex,
36
+ } from '../../utils/encoding/toHex.js'
37
+ import { getContractError } from '../../utils/errors/getContractError.js'
38
+ import {
39
+ type GetNodeErrorReturnType,
40
+ getNodeError,
41
+ } from '../../utils/errors/getNodeError.js'
42
+ import {
43
+ type FormatBlockErrorType,
44
+ formatBlock,
45
+ } from '../../utils/formatters/block.js'
46
+ import { formatLog } from '../../utils/formatters/log.js'
47
+ import {
48
+ type FormatTransactionRequestErrorType,
49
+ formatTransactionRequest,
50
+ } from '../../utils/formatters/transactionRequest.js'
51
+ import {
52
+ type SerializeStateOverrideErrorType,
53
+ serializeStateOverride,
54
+ } from '../../utils/stateOverride.js'
55
+ import {
56
+ type AssertRequestErrorType,
57
+ assertRequest,
58
+ } from '../../utils/transaction/assertRequest.js'
59
+
60
+ type CallExtraProperties = ExactPartial<
61
+ UnionOmit<
62
+ TransactionRequest,
63
+ 'blobs' | 'data' | 'kzg' | 'to' | 'sidecars' | 'value'
64
+ >
65
+ > & {
66
+ /** Account attached to the call (msg.sender). */
67
+ account?: Account | Address | undefined
68
+ }
69
+
70
+ export type SimulateParameters<
71
+ calls extends readonly unknown[] = readonly unknown[],
72
+ > = {
73
+ /** Blocks to simulate. */
74
+ blocks: readonly {
75
+ /** Block overrides. */
76
+ blockOverrides?: BlockOverrides.BlockOverrides | undefined
77
+ /** Calls to execute. */
78
+ calls: Calls<Narrow<calls>, CallExtraProperties>
79
+ /** State overrides. */
80
+ stateOverrides?: StateOverride | undefined
81
+ }[]
82
+ /** Whether to return the full transactions. */
83
+ returnFullTransactions?: boolean
84
+ /** Whether to trace transfers. */
85
+ traceTransfers?: boolean
86
+ /** Whether to enable validation mode. */
87
+ validation?: boolean
88
+ } & (
89
+ | {
90
+ /** The balance of the account at a block number. */
91
+ blockNumber?: bigint | undefined
92
+ blockTag?: undefined
93
+ }
94
+ | {
95
+ blockNumber?: undefined
96
+ /**
97
+ * The balance of the account at a block tag.
98
+ * @default 'latest'
99
+ */
100
+ blockTag?: BlockTag | undefined
101
+ }
102
+ )
103
+
104
+ export type SimulateReturnType<
105
+ calls extends readonly unknown[] = readonly unknown[],
106
+ > = readonly (Block & {
107
+ calls: MulticallResults<
108
+ Narrow<calls>,
109
+ true,
110
+ {
111
+ extraProperties: {
112
+ data: Hex
113
+ gasUsed: bigint
114
+ logs?: Log[] | undefined
115
+ }
116
+ error: Error
117
+ mutability: AbiStateMutability
118
+ }
119
+ >
120
+ })[]
121
+
122
+ export type SimulateErrorType =
123
+ | AssertRequestErrorType
124
+ | DecodeFunctionResultErrorType
125
+ | EncodeFunctionDataErrorType
126
+ | FormatBlockErrorType
127
+ | FormatTransactionRequestErrorType
128
+ | GetNodeErrorReturnType
129
+ | ParseAccountErrorType
130
+ | SerializeStateOverrideErrorType
131
+ | NumberToHexErrorType
132
+ | ErrorType
133
+
134
+ /**
135
+ * Simulates a set of calls on block(s) with optional block and state overrides.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * import { createClient, http, parseEther } from 'viem'
140
+ * import { simulate } from 'viem/actions'
141
+ * import { mainnet } from 'viem/chains'
142
+ *
143
+ * const client = createClient({
144
+ * chain: mainnet,
145
+ * transport: http(),
146
+ * })
147
+ *
148
+ * const result = await simulate(client, {
149
+ * blocks: [{
150
+ * blockOverrides: {
151
+ * number: 69420n,
152
+ * },
153
+ * calls: [{
154
+ * {
155
+ * account: '0x5a0b54d5dc17e482fe8b0bdca5320161b95fb929',
156
+ * data: '0xdeadbeef',
157
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
158
+ * },
159
+ * {
160
+ * account: '0x5a0b54d5dc17e482fe8b0bdca5320161b95fb929',
161
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
162
+ * value: parseEther('1'),
163
+ * },
164
+ * }],
165
+ * stateOverrides: [{
166
+ * address: '0x5a0b54d5dc17e482fe8b0bdca5320161b95fb929',
167
+ * balance: parseEther('10'),
168
+ * }],
169
+ * }]
170
+ * })
171
+ * ```
172
+ *
173
+ * @param client - Client to use.
174
+ * @param parameters - {@link SimulateParameters}
175
+ * @returns Simulated blocks. {@link SimulateReturnType}
176
+ */
177
+ export async function simulate<
178
+ chain extends Chain | undefined,
179
+ const calls extends readonly unknown[],
180
+ >(
181
+ client: Client<Transport, chain>,
182
+ parameters: SimulateParameters<calls>,
183
+ ): Promise<SimulateReturnType<calls>> {
184
+ const {
185
+ blockNumber,
186
+ blockTag = 'latest',
187
+ blocks,
188
+ returnFullTransactions,
189
+ traceTransfers,
190
+ validation,
191
+ } = parameters
192
+
193
+ try {
194
+ const blockStateCalls = []
195
+ for (const block of blocks) {
196
+ const blockOverrides = block.blockOverrides
197
+ ? BlockOverrides.toRpc(block.blockOverrides)
198
+ : undefined
199
+ const calls = block.calls.map((call_) => {
200
+ const call = call_ as Call<unknown, CallExtraProperties>
201
+ const account = call.account ? parseAccount(call.account) : undefined
202
+ const request = {
203
+ ...call,
204
+ data: call.abi ? encodeFunctionData(call) : call.data,
205
+ from: call.from ?? account?.address,
206
+ } as const
207
+ assertRequest(request)
208
+ return formatTransactionRequest(request)
209
+ })
210
+ const stateOverrides = block.stateOverrides
211
+ ? serializeStateOverride(block.stateOverrides)
212
+ : undefined
213
+
214
+ blockStateCalls.push({
215
+ blockOverrides,
216
+ calls,
217
+ stateOverrides,
218
+ })
219
+ }
220
+
221
+ const blockNumberHex = blockNumber ? numberToHex(blockNumber) : undefined
222
+ const block = blockNumberHex || blockTag
223
+
224
+ const result = await client.request({
225
+ method: 'eth_simulateV1',
226
+ params: [
227
+ { blockStateCalls, returnFullTransactions, traceTransfers, validation },
228
+ block,
229
+ ],
230
+ })
231
+
232
+ return result.map((block, i) => ({
233
+ ...formatBlock(block),
234
+ calls: block.calls.map((call, j) => {
235
+ const { abi, args, functionName, to } = blocks[i].calls[j] as Call<
236
+ unknown,
237
+ CallExtraProperties
238
+ >
239
+
240
+ const data = call.error?.data ?? call.returnData
241
+ const gasUsed = BigInt(call.gasUsed)
242
+ const logs = call.logs?.map((log) => formatLog(log))
243
+ const status = call.status === '0x1' ? 'success' : 'failure'
244
+
245
+ const result = abi
246
+ ? decodeFunctionResult({
247
+ abi,
248
+ data,
249
+ functionName,
250
+ })
251
+ : null
252
+
253
+ const error = (() => {
254
+ if (status === 'success') return undefined
255
+
256
+ let error = undefined
257
+ if (call.error?.data === '0x') error = new AbiDecodingZeroDataError()
258
+ else if (call.error) error = new RawContractError(call.error)
259
+
260
+ if (!error) return undefined
261
+ return getContractError(error, {
262
+ abi: (abi ?? []) as Abi,
263
+ address: to,
264
+ args,
265
+ functionName: functionName ?? '<unknown>',
266
+ })
267
+ })()
268
+
269
+ return {
270
+ data,
271
+ gasUsed,
272
+ logs,
273
+ status,
274
+ ...(status === 'success'
275
+ ? {
276
+ result,
277
+ }
278
+ : {
279
+ error,
280
+ }),
281
+ }
282
+ }),
283
+ })) as unknown as SimulateReturnType<calls>
284
+ } catch (e) {
285
+ const cause = e as BaseError
286
+ const error = getNodeError(cause, {})
287
+ if (error instanceof UnknownNodeError) throw cause
288
+ throw error
289
+ }
290
+ }
@@ -6,7 +6,7 @@ export const mainnet = /*#__PURE__*/ defineChain({
6
6
  nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
7
7
  rpcUrls: {
8
8
  default: {
9
- http: ['https://cloudflare-eth.com'],
9
+ http: ['https://eth.merkle.io'],
10
10
  },
11
11
  },
12
12
  blockExplorers: {
@@ -30,6 +30,11 @@ import {
30
30
  type CallReturnType,
31
31
  call,
32
32
  } from '../../actions/public/call.js'
33
+ import {
34
+ type CreateAccessListParameters,
35
+ type CreateAccessListReturnType,
36
+ createAccessList,
37
+ } from '../../actions/public/createAccessList.js'
33
38
  import {
34
39
  type CreateBlockFilterReturnType,
35
40
  createBlockFilter,
@@ -175,6 +180,11 @@ import {
175
180
  type ReadContractReturnType,
176
181
  readContract,
177
182
  } from '../../actions/public/readContract.js'
183
+ import {
184
+ type SimulateParameters,
185
+ type SimulateReturnType,
186
+ simulate,
187
+ } from '../../actions/public/simulate.js'
178
188
  import {
179
189
  type SimulateContractParameters,
180
190
  type SimulateContractReturnType,
@@ -285,6 +295,32 @@ export type PublicActions<
285
295
  * })
286
296
  */
287
297
  call: (parameters: CallParameters<chain>) => Promise<CallReturnType>
298
+ /**
299
+ * Creates an EIP-2930 access list that you can include in a transaction.
300
+ *
301
+ * - Docs: https://viem.sh/docs/actions/public/createAccessList
302
+ * - JSON-RPC Methods: `eth_createAccessList`
303
+ *
304
+ * @param args - {@link CreateAccessListParameters}
305
+ * @returns The call data. {@link CreateAccessListReturnType}
306
+ *
307
+ * @example
308
+ * import { createPublicClient, http } from 'viem'
309
+ * import { mainnet } from 'viem/chains'
310
+ *
311
+ * const client = createPublicClient({
312
+ * chain: mainnet,
313
+ * transport: http(),
314
+ * })
315
+ *
316
+ * const data = await client.createAccessList({
317
+ * data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
318
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
319
+ * })
320
+ */
321
+ createAccessList: (
322
+ parameters: CreateAccessListParameters<chain>,
323
+ ) => Promise<CreateAccessListReturnType>
288
324
  /**
289
325
  * Creates a Filter to listen for new block hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges).
290
326
  *
@@ -1489,6 +1525,51 @@ export type PublicActions<
1489
1525
  sendRawTransaction: (
1490
1526
  args: SendRawTransactionParameters,
1491
1527
  ) => Promise<SendRawTransactionReturnType>
1528
+ /**
1529
+ * Simulates a set of calls on block(s) with optional block and state overrides.
1530
+ *
1531
+ * @example
1532
+ * ```ts
1533
+ * import { createPublicClient, http, parseEther } from 'viem'
1534
+ * import { mainnet } from 'viem/chains'
1535
+ *
1536
+ * const client = createPublicClient({
1537
+ * chain: mainnet,
1538
+ * transport: http(),
1539
+ * })
1540
+ *
1541
+ * const result = await client.simulate({
1542
+ * blocks: [{
1543
+ * blockOverrides: {
1544
+ * number: 69420n,
1545
+ * },
1546
+ * calls: [{
1547
+ * {
1548
+ * account: '0x5a0b54d5dc17e482fe8b0bdca5320161b95fb929',
1549
+ * data: '0xdeadbeef',
1550
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
1551
+ * },
1552
+ * {
1553
+ * account: '0x5a0b54d5dc17e482fe8b0bdca5320161b95fb929',
1554
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
1555
+ * value: parseEther('1'),
1556
+ * },
1557
+ * }],
1558
+ * stateOverrides: [{
1559
+ * address: '0x5a0b54d5dc17e482fe8b0bdca5320161b95fb929',
1560
+ * balance: parseEther('10'),
1561
+ * }],
1562
+ * }]
1563
+ * })
1564
+ * ```
1565
+ *
1566
+ * @param client - Client to use.
1567
+ * @param parameters - {@link SimulateParameters}
1568
+ * @returns Simulated blocks. {@link SimulateReturnType}
1569
+ */
1570
+ simulate: <const calls extends readonly unknown[]>(
1571
+ args: SimulateParameters<calls>,
1572
+ ) => Promise<SimulateReturnType<calls>>
1492
1573
  /**
1493
1574
  * Simulates/validates a contract interaction. This is useful for retrieving **return data** and **revert reasons** of contract write functions.
1494
1575
  *
@@ -1833,6 +1914,7 @@ export function publicActions<
1833
1914
  ): PublicActions<transport, chain, account> {
1834
1915
  return {
1835
1916
  call: (args) => call(client, args),
1917
+ createAccessList: (args) => createAccessList(client, args),
1836
1918
  createBlockFilter: () => createBlockFilter(client),
1837
1919
  createContractEventFilter: (args) =>
1838
1920
  createContractEventFilter(client, args),
@@ -1876,6 +1958,7 @@ export function publicActions<
1876
1958
  prepareTransactionRequest(client as any, args as any) as any,
1877
1959
  readContract: (args) => readContract(client, args),
1878
1960
  sendRawTransaction: (args) => sendRawTransaction(client, args),
1961
+ simulate: (args) => simulate(client, args),
1879
1962
  simulateContract: (args) => simulateContract(client, args),
1880
1963
  verifyMessage: (args) => verifyMessage(client, args),
1881
1964
  verifySiweMessage: (args) => verifySiweMessage(client, args),
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.21.59'
1
+ export const version = '2.22.0'
package/index.ts CHANGED
@@ -36,6 +36,10 @@ export {
36
36
  parseAbiParameter,
37
37
  parseAbiParameters,
38
38
  } from 'abitype'
39
+ export type {
40
+ BlockOverrides,
41
+ Rpc as RpcBlockOverrides,
42
+ } from 'ox/BlockOverrides'
39
43
 
40
44
  export {
41
45
  getContract,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.21.59",
4
+ "version": "2.22.0",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -177,7 +177,7 @@
177
177
  "@scure/bip39": "1.5.0",
178
178
  "abitype": "1.0.7",
179
179
  "isows": "1.0.6",
180
- "ox": "0.4.4",
180
+ "ox": "0.6.0",
181
181
  "webauthn-p256": "0.0.10",
182
182
  "ws": "8.18.0"
183
183
  },