viem 1.4.2 → 1.5.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 (216) hide show
  1. package/dist/cjs/accounts/index.js +1 -1
  2. package/dist/cjs/accounts/index.js.map +1 -1
  3. package/dist/cjs/accounts/utils/signMessage.js +1 -1
  4. package/dist/cjs/accounts/utils/signMessage.js.map +1 -1
  5. package/dist/cjs/accounts/utils/signTypedData.js +1 -1
  6. package/dist/cjs/accounts/utils/signTypedData.js.map +1 -1
  7. package/dist/cjs/actions/public/createContractEventFilter.js.map +1 -1
  8. package/dist/cjs/actions/public/createEventFilter.js +16 -8
  9. package/dist/cjs/actions/public/createEventFilter.js.map +1 -1
  10. package/dist/cjs/actions/public/getBlock.js +3 -1
  11. package/dist/cjs/actions/public/getBlock.js.map +1 -1
  12. package/dist/cjs/actions/public/getBlockNumber.js +2 -2
  13. package/dist/cjs/actions/public/getBlockNumber.js.map +1 -1
  14. package/dist/cjs/actions/public/getFilterChanges.js.map +1 -1
  15. package/dist/cjs/actions/public/getFilterLogs.js +1 -1
  16. package/dist/cjs/actions/public/getFilterLogs.js.map +1 -1
  17. package/dist/cjs/actions/public/getLogs.js +16 -10
  18. package/dist/cjs/actions/public/getLogs.js.map +1 -1
  19. package/dist/cjs/actions/public/getTransaction.js +2 -1
  20. package/dist/cjs/actions/public/getTransaction.js.map +1 -1
  21. package/dist/cjs/actions/public/watchBlockNumber.js +1 -1
  22. package/dist/cjs/actions/public/watchBlockNumber.js.map +1 -1
  23. package/dist/cjs/actions/public/watchBlocks.js +2 -1
  24. package/dist/cjs/actions/public/watchBlocks.js.map +1 -1
  25. package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
  26. package/dist/cjs/actions/public/watchEvent.js +4 -2
  27. package/dist/cjs/actions/public/watchEvent.js.map +1 -1
  28. package/dist/cjs/clients/createClient.js +2 -1
  29. package/dist/cjs/clients/createClient.js.map +1 -1
  30. package/dist/cjs/clients/createPublicClient.js.map +1 -1
  31. package/dist/cjs/clients/createTestClient.js.map +1 -1
  32. package/dist/cjs/clients/createWalletClient.js.map +1 -1
  33. package/dist/cjs/clients/decorators/public.js.map +1 -1
  34. package/dist/cjs/constants/number.js +101 -0
  35. package/dist/cjs/constants/number.js.map +1 -0
  36. package/dist/cjs/errors/version.js +1 -1
  37. package/dist/cjs/index.js +110 -7
  38. package/dist/cjs/index.js.map +1 -1
  39. package/dist/cjs/utils/formatters/block.js.map +1 -1
  40. package/dist/cjs/utils/formatters/formatter.js +1 -0
  41. package/dist/cjs/utils/formatters/formatter.js.map +1 -1
  42. package/dist/cjs/utils/formatters/transaction.js.map +1 -1
  43. package/dist/cjs/utils/promise/withCache.js +3 -3
  44. package/dist/cjs/utils/promise/withCache.js.map +1 -1
  45. package/dist/cjs/utils/signature/hexToSignature.js +12 -0
  46. package/dist/cjs/utils/signature/hexToSignature.js.map +1 -0
  47. package/dist/cjs/utils/signature/signatureToHex.js.map +1 -0
  48. package/dist/esm/accounts/index.js +1 -1
  49. package/dist/esm/accounts/index.js.map +1 -1
  50. package/dist/esm/accounts/utils/signMessage.js +1 -1
  51. package/dist/esm/accounts/utils/signMessage.js.map +1 -1
  52. package/dist/esm/accounts/utils/signTypedData.js +1 -1
  53. package/dist/esm/accounts/utils/signTypedData.js.map +1 -1
  54. package/dist/esm/actions/public/createContractEventFilter.js.map +1 -1
  55. package/dist/esm/actions/public/createEventFilter.js +16 -8
  56. package/dist/esm/actions/public/createEventFilter.js.map +1 -1
  57. package/dist/esm/actions/public/getBlock.js +3 -1
  58. package/dist/esm/actions/public/getBlock.js.map +1 -1
  59. package/dist/esm/actions/public/getBlockNumber.js +2 -2
  60. package/dist/esm/actions/public/getBlockNumber.js.map +1 -1
  61. package/dist/esm/actions/public/getFilterChanges.js.map +1 -1
  62. package/dist/esm/actions/public/getFilterLogs.js +1 -1
  63. package/dist/esm/actions/public/getFilterLogs.js.map +1 -1
  64. package/dist/esm/actions/public/getLogs.js +16 -10
  65. package/dist/esm/actions/public/getLogs.js.map +1 -1
  66. package/dist/esm/actions/public/getTransaction.js +2 -1
  67. package/dist/esm/actions/public/getTransaction.js.map +1 -1
  68. package/dist/esm/actions/public/watchBlockNumber.js +1 -1
  69. package/dist/esm/actions/public/watchBlockNumber.js.map +1 -1
  70. package/dist/esm/actions/public/watchBlocks.js +2 -1
  71. package/dist/esm/actions/public/watchBlocks.js.map +1 -1
  72. package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
  73. package/dist/esm/actions/public/watchEvent.js +4 -2
  74. package/dist/esm/actions/public/watchEvent.js.map +1 -1
  75. package/dist/esm/clients/createClient.js +2 -1
  76. package/dist/esm/clients/createClient.js.map +1 -1
  77. package/dist/esm/clients/createPublicClient.js.map +1 -1
  78. package/dist/esm/clients/createTestClient.js.map +1 -1
  79. package/dist/esm/clients/createWalletClient.js.map +1 -1
  80. package/dist/esm/clients/decorators/public.js.map +1 -1
  81. package/dist/esm/constants/number.js +97 -0
  82. package/dist/esm/constants/number.js.map +1 -0
  83. package/dist/esm/errors/version.js +1 -1
  84. package/dist/esm/index.js +4 -1
  85. package/dist/esm/index.js.map +1 -1
  86. package/dist/esm/utils/formatters/block.js.map +1 -1
  87. package/dist/esm/utils/formatters/formatter.js +1 -0
  88. package/dist/esm/utils/formatters/formatter.js.map +1 -1
  89. package/dist/esm/utils/formatters/transaction.js.map +1 -1
  90. package/dist/esm/utils/promise/withCache.js +3 -3
  91. package/dist/esm/utils/promise/withCache.js.map +1 -1
  92. package/dist/esm/utils/signature/hexToSignature.js +18 -0
  93. package/dist/esm/utils/signature/hexToSignature.js.map +1 -0
  94. package/dist/esm/utils/signature/signatureToHex.js +21 -0
  95. package/dist/esm/utils/signature/signatureToHex.js.map +1 -0
  96. package/dist/types/accounts/index.d.ts +1 -1
  97. package/dist/types/accounts/index.d.ts.map +1 -1
  98. package/dist/types/actions/public/createContractEventFilter.d.ts +5 -5
  99. package/dist/types/actions/public/createContractEventFilter.d.ts.map +1 -1
  100. package/dist/types/actions/public/createEventFilter.d.ts +20 -7
  101. package/dist/types/actions/public/createEventFilter.d.ts.map +1 -1
  102. package/dist/types/actions/public/getBlock.d.ts +5 -5
  103. package/dist/types/actions/public/getBlock.d.ts.map +1 -1
  104. package/dist/types/actions/public/getBlockNumber.d.ts +4 -2
  105. package/dist/types/actions/public/getBlockNumber.d.ts.map +1 -1
  106. package/dist/types/actions/public/getFilterChanges.d.ts +5 -8
  107. package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
  108. package/dist/types/actions/public/getFilterLogs.d.ts +5 -4
  109. package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
  110. package/dist/types/actions/public/getLogs.d.ts +17 -6
  111. package/dist/types/actions/public/getLogs.d.ts.map +1 -1
  112. package/dist/types/actions/public/getTransaction.d.ts +4 -4
  113. package/dist/types/actions/public/getTransaction.d.ts.map +1 -1
  114. package/dist/types/actions/public/watchBlocks.d.ts +10 -10
  115. package/dist/types/actions/public/watchBlocks.d.ts.map +1 -1
  116. package/dist/types/actions/public/watchContractEvent.d.ts +1 -1
  117. package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
  118. package/dist/types/actions/public/watchEvent.d.ts +19 -8
  119. package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
  120. package/dist/types/chains/formatters/celo.d.ts +4 -0
  121. package/dist/types/chains/formatters/celo.d.ts.map +1 -1
  122. package/dist/types/chains/formatters/optimism.d.ts +5 -3
  123. package/dist/types/chains/formatters/optimism.d.ts.map +1 -1
  124. package/dist/types/chains/index.d.ts +44 -12
  125. package/dist/types/chains/index.d.ts.map +1 -1
  126. package/dist/types/clients/createClient.d.ts +7 -0
  127. package/dist/types/clients/createClient.d.ts.map +1 -1
  128. package/dist/types/clients/createPublicClient.d.ts +1 -1
  129. package/dist/types/clients/createPublicClient.d.ts.map +1 -1
  130. package/dist/types/clients/createTestClient.d.ts +1 -1
  131. package/dist/types/clients/createTestClient.d.ts.map +1 -1
  132. package/dist/types/clients/createWalletClient.d.ts +1 -1
  133. package/dist/types/clients/createWalletClient.d.ts.map +1 -1
  134. package/dist/types/clients/decorators/public.d.ts +10 -9
  135. package/dist/types/clients/decorators/public.d.ts.map +1 -1
  136. package/dist/types/constants/number.d.ts +97 -0
  137. package/dist/types/constants/number.d.ts.map +1 -0
  138. package/dist/types/errors/version.d.ts +1 -1
  139. package/dist/types/index.d.ts +4 -1
  140. package/dist/types/index.d.ts.map +1 -1
  141. package/dist/types/types/block.d.ts +7 -7
  142. package/dist/types/types/block.d.ts.map +1 -1
  143. package/dist/types/types/contract.d.ts +1 -1
  144. package/dist/types/types/contract.d.ts.map +1 -1
  145. package/dist/types/types/filter.d.ts +7 -3
  146. package/dist/types/types/filter.d.ts.map +1 -1
  147. package/dist/types/types/formatter.d.ts +3 -0
  148. package/dist/types/types/formatter.d.ts.map +1 -1
  149. package/dist/types/types/log.d.ts +8 -8
  150. package/dist/types/types/log.d.ts.map +1 -1
  151. package/dist/types/types/misc.d.ts.map +1 -1
  152. package/dist/types/types/rpc.d.ts +3 -3
  153. package/dist/types/types/rpc.d.ts.map +1 -1
  154. package/dist/types/types/transaction.d.ts +8 -8
  155. package/dist/types/types/transaction.d.ts.map +1 -1
  156. package/dist/types/utils/formatters/block.d.ts +13 -3
  157. package/dist/types/utils/formatters/block.d.ts.map +1 -1
  158. package/dist/types/utils/formatters/formatter.d.ts +1 -0
  159. package/dist/types/utils/formatters/formatter.d.ts.map +1 -1
  160. package/dist/types/utils/formatters/transaction.d.ts +10 -3
  161. package/dist/types/utils/formatters/transaction.d.ts.map +1 -1
  162. package/dist/types/utils/formatters/transactionReceipt.d.ts +1 -0
  163. package/dist/types/utils/formatters/transactionReceipt.d.ts.map +1 -1
  164. package/dist/types/utils/formatters/transactionRequest.d.ts +1 -0
  165. package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
  166. package/dist/types/utils/promise/withCache.d.ts +3 -3
  167. package/dist/types/utils/promise/withCache.d.ts.map +1 -1
  168. package/dist/types/utils/signature/hexToSignature.d.ts +13 -0
  169. package/dist/types/utils/signature/hexToSignature.d.ts.map +1 -0
  170. package/dist/types/utils/signature/signatureToHex.d.ts +17 -0
  171. package/dist/types/utils/signature/signatureToHex.d.ts.map +1 -0
  172. package/package.json +1 -1
  173. package/src/accounts/index.ts +1 -1
  174. package/src/accounts/utils/signMessage.ts +1 -1
  175. package/src/accounts/utils/signTypedData.ts +1 -1
  176. package/src/actions/public/createContractEventFilter.ts +30 -7
  177. package/src/actions/public/createEventFilter.ts +78 -24
  178. package/src/actions/public/getBlock.ts +18 -8
  179. package/src/actions/public/getBlockNumber.ts +5 -3
  180. package/src/actions/public/getFilterChanges.ts +46 -10
  181. package/src/actions/public/getFilterLogs.ts +26 -10
  182. package/src/actions/public/getLogs.ts +73 -18
  183. package/src/actions/public/getTransaction.ts +15 -8
  184. package/src/actions/public/watchBlockNumber.ts +1 -1
  185. package/src/actions/public/watchBlocks.ts +37 -18
  186. package/src/actions/public/watchContractEvent.ts +5 -5
  187. package/src/actions/public/watchEvent.ts +50 -17
  188. package/src/clients/createClient.ts +9 -0
  189. package/src/clients/createPublicClient.ts +7 -1
  190. package/src/clients/createTestClient.ts +7 -1
  191. package/src/clients/createWalletClient.ts +7 -1
  192. package/src/clients/decorators/public.ts +114 -25
  193. package/src/constants/number.ts +98 -0
  194. package/src/errors/version.ts +1 -1
  195. package/src/index.ts +101 -1
  196. package/src/types/block.ts +25 -10
  197. package/src/types/contract.ts +7 -3
  198. package/src/types/filter.ts +32 -26
  199. package/src/types/formatter.ts +9 -0
  200. package/src/types/log.ts +13 -8
  201. package/src/types/misc.ts +3 -0
  202. package/src/types/rpc.ts +20 -6
  203. package/src/types/transaction.ts +22 -11
  204. package/src/utils/formatters/block.ts +31 -4
  205. package/src/utils/formatters/formatter.ts +1 -0
  206. package/src/utils/formatters/transaction.ts +25 -2
  207. package/src/utils/promise/withCache.ts +5 -5
  208. package/src/utils/signature/hexToSignature.ts +20 -0
  209. package/src/utils/signature/signatureToHex.ts +26 -0
  210. package/dist/cjs/accounts/utils/signatureToHex.js.map +0 -1
  211. package/dist/esm/accounts/utils/signatureToHex.js +0 -7
  212. package/dist/esm/accounts/utils/signatureToHex.js.map +0 -1
  213. package/dist/types/accounts/utils/signatureToHex.d.ts +0 -3
  214. package/dist/types/accounts/utils/signatureToHex.d.ts.map +0 -1
  215. package/src/accounts/utils/signatureToHex.ts +0 -12
  216. /package/dist/cjs/{accounts/utils → utils/signature}/signatureToHex.js +0 -0
@@ -1,4 +1,4 @@
1
- import type { AbiEvent, Address } from 'abitype'
1
+ import type { AbiEvent, Address, Narrow } from 'abitype'
2
2
 
3
3
  import type { Client } from '../../clients/createClient.js'
4
4
  import type { Transport } from '../../clients/transports/createTransport.js'
@@ -19,24 +19,38 @@ import {
19
19
  } from './createEventFilter.js'
20
20
  import { getBlockNumber } from './getBlockNumber.js'
21
21
  import { getFilterChanges } from './getFilterChanges.js'
22
- import { getLogs } from './getLogs.js'
22
+ import { type GetLogsParameters, getLogs } from './getLogs.js'
23
23
  import { uninstallFilter } from './uninstallFilter.js'
24
24
 
25
25
  export type WatchEventOnLogsParameter<
26
26
  TAbiEvent extends AbiEvent | undefined = undefined,
27
+ TAbiEvents extends
28
+ | readonly AbiEvent[]
29
+ | readonly unknown[]
30
+ | undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
27
31
  TStrict extends boolean | undefined = undefined,
28
32
  TEventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
29
- > = Log<bigint, number, TAbiEvent, TStrict, [TAbiEvent], TEventName>[]
33
+ > = Log<bigint, number, false, TAbiEvent, TStrict, TAbiEvents, TEventName>[]
30
34
  export type WatchEventOnLogsFn<
31
35
  TAbiEvent extends AbiEvent | undefined = undefined,
36
+ TAbiEvents extends
37
+ | readonly AbiEvent[]
38
+ | readonly unknown[]
39
+ | undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
32
40
  TStrict extends boolean | undefined = undefined,
33
- TEventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
34
- > = (logs: WatchEventOnLogsParameter<TAbiEvent, TStrict, TEventName>) => void
41
+ _EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
42
+ > = (
43
+ logs: WatchEventOnLogsParameter<TAbiEvent, TAbiEvents, TStrict, _EventName>,
44
+ ) => void
35
45
 
36
46
  export type WatchEventParameters<
37
47
  TAbiEvent extends AbiEvent | undefined = undefined,
48
+ TAbiEvents extends
49
+ | readonly AbiEvent[]
50
+ | readonly unknown[]
51
+ | undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
38
52
  TStrict extends boolean | undefined = undefined,
39
- TEventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
53
+ _EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
40
54
  > = {
41
55
  /** The address of the contract. */
42
56
  address?: Address | Address[]
@@ -48,13 +62,24 @@ export type WatchEventParameters<
48
62
  /** The callback to call when an error occurred when trying to get for a new block. */
49
63
  onError?: (error: Error) => void
50
64
  /** The callback to call when new event logs are received. */
51
- onLogs: WatchEventOnLogsFn<TAbiEvent, TStrict, TEventName>
65
+ onLogs: WatchEventOnLogsFn<TAbiEvent, TAbiEvents, TStrict, _EventName>
52
66
  /** Polling frequency (in ms). Defaults to Client's pollingInterval config. */
53
67
  pollingInterval?: number
54
68
  } & (
55
69
  | {
56
- event: TAbiEvent
57
- args?: MaybeExtractEventArgsFromAbi<[TAbiEvent], TEventName>
70
+ event: Narrow<TAbiEvent>
71
+ events?: never
72
+ args?: MaybeExtractEventArgsFromAbi<TAbiEvents, _EventName>
73
+ /**
74
+ * Whether or not the logs must match the indexed/non-indexed arguments on `event`.
75
+ * @default false
76
+ */
77
+ strict?: TStrict
78
+ }
79
+ | {
80
+ event?: never
81
+ events?: Narrow<TAbiEvents>
82
+ args?: never
58
83
  /**
59
84
  * Whether or not the logs must match the indexed/non-indexed arguments on `event`.
60
85
  * @default false
@@ -63,6 +88,7 @@ export type WatchEventParameters<
63
88
  }
64
89
  | {
65
90
  event?: never
91
+ events?: never
66
92
  args?: never
67
93
  strict?: never
68
94
  }
@@ -104,9 +130,13 @@ export type WatchEventReturnType = () => void
104
130
  */
105
131
  export function watchEvent<
106
132
  TChain extends Chain | undefined,
107
- TAbiEvent extends AbiEvent | undefined,
108
- TEventName extends string | undefined,
133
+ TAbiEvent extends AbiEvent | undefined = undefined,
134
+ TAbiEvents extends
135
+ | readonly AbiEvent[]
136
+ | readonly unknown[]
137
+ | undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
109
138
  TStrict extends boolean | undefined = undefined,
139
+ _EventName extends string | undefined = undefined,
110
140
  >(
111
141
  client: Client<Transport, TChain>,
112
142
  {
@@ -114,11 +144,12 @@ export function watchEvent<
114
144
  args,
115
145
  batch = true,
116
146
  event,
147
+ events,
117
148
  onError,
118
149
  onLogs,
119
150
  pollingInterval = client.pollingInterval,
120
151
  strict: strict_,
121
- }: WatchEventParameters<TAbiEvent, TStrict>,
152
+ }: WatchEventParameters<TAbiEvent, TAbiEvents, TStrict>,
122
153
  ): WatchEventReturnType {
123
154
  const observerId = stringify([
124
155
  'watchEvent',
@@ -133,7 +164,7 @@ export function watchEvent<
133
164
 
134
165
  return observe(observerId, { onLogs, onError }, (emit) => {
135
166
  let previousBlockNumber: bigint
136
- let filter: Filter<'event', [TAbiEvent], TEventName, any>
167
+ let filter: Filter<'event', TAbiEvents, _EventName, any>
137
168
  let initialized = false
138
169
 
139
170
  const unwatch = poll(
@@ -144,11 +175,12 @@ export function watchEvent<
144
175
  address,
145
176
  args,
146
177
  event: event!,
178
+ events,
147
179
  strict,
148
180
  } as unknown as CreateEventFilterParameters)) as unknown as Filter<
149
181
  'event',
150
- [TAbiEvent],
151
- TEventName
182
+ TAbiEvents,
183
+ _EventName
152
184
  >
153
185
  } catch {}
154
186
  initialized = true
@@ -173,10 +205,11 @@ export function watchEvent<
173
205
  logs = await getLogs(client, {
174
206
  address,
175
207
  args,
208
+ event: event!,
209
+ events,
176
210
  fromBlock: previousBlockNumber + 1n,
177
211
  toBlock: blockNumber,
178
- event: event!,
179
- })
212
+ } as unknown as GetLogsParameters)
180
213
  } else {
181
214
  logs = []
182
215
  }
@@ -29,6 +29,11 @@ export type ClientConfig<
29
29
  multicall?: boolean | Prettify<MulticallBatchOptions> | undefined
30
30
  }
31
31
  | undefined
32
+ /**
33
+ * Time (in ms) that cached data will remain in memory.
34
+ * @default 4_000
35
+ */
36
+ cacheTime?: number | undefined
32
37
  /** Chain for the client. */
33
38
  chain?: Chain | undefined | chain
34
39
  /** A key for the client. */
@@ -79,6 +84,8 @@ type Client_Base<
79
84
  account: account
80
85
  /** Flags for batch settings. */
81
86
  batch?: ClientConfig['batch']
87
+ /** Time (in ms) that cached data will remain in memory. */
88
+ cacheTime: number
82
89
  /** Chain for the client. */
83
90
  chain: chain
84
91
  /** A key for the client. */
@@ -135,6 +142,7 @@ export function createClient<
135
142
  export function createClient(parameters: ClientConfig): Client {
136
143
  const {
137
144
  batch,
145
+ cacheTime = parameters.pollingInterval ?? 4_000,
138
146
  key = 'base',
139
147
  name = 'Base Client',
140
148
  pollingInterval = 4_000,
@@ -154,6 +162,7 @@ export function createClient(parameters: ClientConfig): Client {
154
162
  const client = {
155
163
  account,
156
164
  batch,
165
+ cacheTime,
157
166
  chain,
158
167
  key,
159
168
  name,
@@ -11,7 +11,13 @@ export type PublicClientConfig<
11
11
  > = Prettify<
12
12
  Pick<
13
13
  ClientConfig<transport, chain>,
14
- 'batch' | 'chain' | 'key' | 'name' | 'pollingInterval' | 'transport'
14
+ | 'batch'
15
+ | 'cacheTime'
16
+ | 'chain'
17
+ | 'key'
18
+ | 'name'
19
+ | 'pollingInterval'
20
+ | 'transport'
15
21
  >
16
22
  >
17
23
 
@@ -21,7 +21,13 @@ export type TestClientConfig<
21
21
  > = Prettify<
22
22
  Pick<
23
23
  ClientConfig<transport, chain, accountOrAddress>,
24
- 'account' | 'chain' | 'key' | 'name' | 'pollingInterval' | 'transport'
24
+ | 'account'
25
+ | 'cacheTime'
26
+ | 'chain'
27
+ | 'key'
28
+ | 'name'
29
+ | 'pollingInterval'
30
+ | 'transport'
25
31
  > & {
26
32
  /** Mode of the test client. */
27
33
  mode: mode | ('anvil' | 'hardhat' | 'ganache') // TODO: Type utility that expands `TestClientMode`
@@ -19,7 +19,13 @@ export type WalletClientConfig<
19
19
  > = Prettify<
20
20
  Pick<
21
21
  ClientConfig<transport, chain, accountOrAddress>,
22
- 'account' | 'chain' | 'key' | 'name' | 'pollingInterval' | 'transport'
22
+ | 'account'
23
+ | 'cacheTime'
24
+ | 'chain'
25
+ | 'key'
26
+ | 'name'
27
+ | 'pollingInterval'
28
+ | 'transport'
23
29
  >
24
30
  >
25
31
 
@@ -197,6 +197,7 @@ import {
197
197
  watchPendingTransactions,
198
198
  } from '../../actions/public/watchPendingTransactions.js'
199
199
  import type { Account } from '../../types/account.js'
200
+ import type { BlockNumber, BlockTag } from '../../types/block.js'
200
201
  import type { Chain } from '../../types/chain.js'
201
202
  import type {
202
203
  ContractFunctionConfig,
@@ -281,10 +282,26 @@ export type PublicActions<
281
282
  TEventName extends string | undefined,
282
283
  TArgs extends MaybeExtractEventArgsFromAbi<TAbi, TEventName> | undefined,
283
284
  TStrict extends boolean | undefined = undefined,
285
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
286
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
284
287
  >(
285
- args: CreateContractEventFilterParameters<TAbi, TEventName, TArgs, TStrict>,
288
+ args: CreateContractEventFilterParameters<
289
+ TAbi,
290
+ TEventName,
291
+ TArgs,
292
+ TStrict,
293
+ TFromBlock,
294
+ TToBlock
295
+ >,
286
296
  ) => Promise<
287
- CreateContractEventFilterReturnType<TAbi, TEventName, TArgs, TStrict>
297
+ CreateContractEventFilterReturnType<
298
+ TAbi,
299
+ TEventName,
300
+ TArgs,
301
+ TStrict,
302
+ TFromBlock,
303
+ TToBlock
304
+ >
288
305
  >
289
306
  /**
290
307
  * Creates a [`Filter`](https://viem.sh/docs/glossary/types.html#filter) to listen for new events that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges.html).
@@ -308,23 +325,38 @@ export type PublicActions<
308
325
  * })
309
326
  */
310
327
  createEventFilter: <
311
- TAbiEvent extends AbiEvent | undefined,
328
+ TAbiEvent extends AbiEvent | undefined = undefined,
329
+ TAbiEvents extends
330
+ | readonly AbiEvent[]
331
+ | readonly unknown[]
332
+ | undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
312
333
  TStrict extends boolean | undefined = undefined,
313
- _Abi extends Abi | readonly unknown[] = [TAbiEvent],
334
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
335
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
314
336
  _EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
315
337
  _Args extends
316
- | MaybeExtractEventArgsFromAbi<_Abi, _EventName>
338
+ | MaybeExtractEventArgsFromAbi<TAbiEvents, _EventName>
317
339
  | undefined = undefined,
318
340
  >(
319
341
  args?: CreateEventFilterParameters<
320
342
  TAbiEvent,
343
+ TAbiEvents,
321
344
  TStrict,
322
- _Abi,
345
+ TFromBlock,
346
+ TToBlock,
323
347
  _EventName,
324
348
  _Args
325
349
  >,
326
350
  ) => Promise<
327
- CreateEventFilterReturnType<TAbiEvent, TStrict, _Abi, _EventName, _Args>
351
+ CreateEventFilterReturnType<
352
+ TAbiEvent,
353
+ TAbiEvents,
354
+ TStrict,
355
+ TFromBlock,
356
+ TToBlock,
357
+ _EventName,
358
+ _Args
359
+ >
328
360
  >
329
361
  /**
330
362
  * Creates a Filter to listen for new pending transaction hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges.html).
@@ -462,7 +494,12 @@ export type PublicActions<
462
494
  * })
463
495
  * const block = await client.getBlock()
464
496
  */
465
- getBlock: (args?: GetBlockParameters) => Promise<GetBlockReturnType<TChain>>
497
+ getBlock: <
498
+ TIncludeTransactions extends boolean = false,
499
+ TBlockTag extends BlockTag = 'latest',
500
+ >(
501
+ args?: GetBlockParameters<TIncludeTransactions, TBlockTag>,
502
+ ) => Promise<GetBlockReturnType<TChain, TIncludeTransactions, TBlockTag>>
466
503
  /**
467
504
  * Returns the number of the most recent block seen.
468
505
  *
@@ -807,13 +844,29 @@ export type PublicActions<
807
844
  */
808
845
  getFilterChanges: <
809
846
  TFilterType extends FilterType,
810
- TAbi extends Abi | readonly unknown[],
847
+ TAbi extends Abi | readonly unknown[] | undefined,
811
848
  TEventName extends string | undefined,
812
849
  TStrict extends boolean | undefined = undefined,
850
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
851
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
813
852
  >(
814
- args: GetFilterChangesParameters<TFilterType, TAbi, TEventName, TStrict>,
853
+ args: GetFilterChangesParameters<
854
+ TFilterType,
855
+ TAbi,
856
+ TEventName,
857
+ TStrict,
858
+ TFromBlock,
859
+ TToBlock
860
+ >,
815
861
  ) => Promise<
816
- GetFilterChangesReturnType<TFilterType, TAbi, TEventName, TStrict>
862
+ GetFilterChangesReturnType<
863
+ TFilterType,
864
+ TAbi,
865
+ TEventName,
866
+ TStrict,
867
+ TFromBlock,
868
+ TToBlock
869
+ >
817
870
  >
818
871
  /**
819
872
  * Returns a list of event logs since the filter was created.
@@ -842,12 +895,22 @@ export type PublicActions<
842
895
  * const logs = await client.getFilterLogs({ filter })
843
896
  */
844
897
  getFilterLogs: <
845
- TAbi extends Abi | readonly unknown[],
898
+ TAbi extends Abi | readonly unknown[] | undefined,
846
899
  TEventName extends string | undefined,
847
900
  TStrict extends boolean | undefined = undefined,
901
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
902
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
848
903
  >(
849
- args: GetFilterLogsParameters<TAbi, TEventName, TStrict>,
850
- ) => Promise<GetFilterLogsReturnType<TAbi, TEventName, TStrict>>
904
+ args: GetFilterLogsParameters<
905
+ TAbi,
906
+ TEventName,
907
+ TStrict,
908
+ TFromBlock,
909
+ TToBlock
910
+ >,
911
+ ) => Promise<
912
+ GetFilterLogsReturnType<TAbi, TEventName, TStrict, TFromBlock, TToBlock>
913
+ >
851
914
  /**
852
915
  * Returns the current price of gas (in wei).
853
916
  *
@@ -888,11 +951,25 @@ export type PublicActions<
888
951
  * const logs = await client.getLogs()
889
952
  */
890
953
  getLogs: <
891
- TAbiEvent extends AbiEvent | undefined,
954
+ TAbiEvent extends AbiEvent | undefined = undefined,
955
+ TAbiEvents extends
956
+ | readonly AbiEvent[]
957
+ | readonly unknown[]
958
+ | undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
892
959
  TStrict extends boolean | undefined = undefined,
960
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
961
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
893
962
  >(
894
- args?: GetLogsParameters<TAbiEvent, TStrict>,
895
- ) => Promise<GetLogsReturnType<TAbiEvent, TStrict>>
963
+ args?: GetLogsParameters<
964
+ TAbiEvent,
965
+ TAbiEvents,
966
+ TStrict,
967
+ TFromBlock,
968
+ TToBlock
969
+ >,
970
+ ) => Promise<
971
+ GetLogsReturnType<TAbiEvent, TAbiEvents, TStrict, TFromBlock, TToBlock>
972
+ >
896
973
  /**
897
974
  * Returns the value from a storage slot at a given address.
898
975
  *
@@ -941,9 +1018,9 @@ export type PublicActions<
941
1018
  * hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
942
1019
  * })
943
1020
  */
944
- getTransaction: (
945
- args: GetTransactionParameters,
946
- ) => Promise<GetTransactionReturnType<TChain>>
1021
+ getTransaction: <TBlockTag extends BlockTag = 'latest'>(
1022
+ args: GetTransactionParameters<TBlockTag>,
1023
+ ) => Promise<GetTransactionReturnType<TChain, TBlockTag>>
947
1024
  /**
948
1025
  * Returns the number of blocks passed (confirmations) since the transaction was processed on a block.
949
1026
  *
@@ -1265,8 +1342,16 @@ export type PublicActions<
1265
1342
  * onBlock: (block) => console.log(block),
1266
1343
  * })
1267
1344
  */
1268
- watchBlocks: (
1269
- args: WatchBlocksParameters<TTransport, TChain>,
1345
+ watchBlocks: <
1346
+ TIncludeTransactions extends boolean = false,
1347
+ TBlockTag extends BlockTag = 'latest',
1348
+ >(
1349
+ args: WatchBlocksParameters<
1350
+ TTransport,
1351
+ TChain,
1352
+ TIncludeTransactions,
1353
+ TBlockTag
1354
+ >,
1270
1355
  ) => WatchBlocksReturnType
1271
1356
  /**
1272
1357
  * Watches and returns emitted contract event logs.
@@ -1336,10 +1421,14 @@ export type PublicActions<
1336
1421
  * })
1337
1422
  */
1338
1423
  watchEvent: <
1339
- TAbiEvent extends AbiEvent | undefined,
1424
+ TAbiEvent extends AbiEvent | undefined = undefined,
1425
+ TAbiEvents extends
1426
+ | readonly AbiEvent[]
1427
+ | readonly unknown[]
1428
+ | undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
1340
1429
  TStrict extends boolean | undefined = undefined,
1341
1430
  >(
1342
- args: WatchEventParameters<TAbiEvent, TStrict>,
1431
+ args: WatchEventParameters<TAbiEvent, TAbiEvents, TStrict>,
1343
1432
  ) => WatchEventReturnType
1344
1433
  /**
1345
1434
  * Watches and returns pending transaction hashes.
@@ -1406,7 +1495,7 @@ export function publicActions<
1406
1495
  getFilterChanges: (args) => getFilterChanges(client, args),
1407
1496
  getFilterLogs: (args) => getFilterLogs(client, args),
1408
1497
  getGasPrice: () => getGasPrice(client),
1409
- getLogs: (args) => getLogs(client, args),
1498
+ getLogs: (args) => getLogs(client, args as any),
1410
1499
  getStorageAt: (args) => getStorageAt(client, args),
1411
1500
  getTransaction: (args) => getTransaction(client, args),
1412
1501
  getTransactionConfirmations: (args) =>
@@ -0,0 +1,98 @@
1
+ export const maxInt8 = 2n ** (8n - 1n)
2
+ export const maxInt16 = 2n ** (16n - 1n)
3
+ export const maxInt24 = 2n ** (24n - 1n)
4
+ export const maxInt32 = 2n ** (32n - 1n)
5
+ export const maxInt40 = 2n ** (40n - 1n)
6
+ export const maxInt48 = 2n ** (48n - 1n)
7
+ export const maxInt56 = 2n ** (56n - 1n)
8
+ export const maxInt64 = 2n ** (64n - 1n)
9
+ export const maxInt72 = 2n ** (72n - 1n)
10
+ export const maxInt80 = 2n ** (80n - 1n)
11
+ export const maxInt88 = 2n ** (88n - 1n)
12
+ export const maxInt96 = 2n ** (96n - 1n)
13
+ export const maxInt104 = 2n ** (104n - 1n)
14
+ export const maxInt112 = 2n ** (112n - 1n)
15
+ export const maxInt120 = 2n ** (120n - 1n)
16
+ export const maxInt128 = 2n ** (128n - 1n)
17
+ export const maxInt136 = 2n ** (136n - 1n)
18
+ export const maxInt144 = 2n ** (144n - 1n)
19
+ export const maxInt152 = 2n ** (152n - 1n)
20
+ export const maxInt160 = 2n ** (160n - 1n)
21
+ export const maxInt168 = 2n ** (168n - 1n)
22
+ export const maxInt176 = 2n ** (176n - 1n)
23
+ export const maxInt184 = 2n ** (184n - 1n)
24
+ export const maxInt192 = 2n ** (192n - 1n)
25
+ export const maxInt200 = 2n ** (200n - 1n)
26
+ export const maxInt208 = 2n ** (208n - 1n)
27
+ export const maxInt216 = 2n ** (216n - 1n)
28
+ export const maxInt224 = 2n ** (224n - 1n)
29
+ export const maxInt232 = 2n ** (232n - 1n)
30
+ export const maxInt240 = 2n ** (240n - 1n)
31
+ export const maxInt248 = 2n ** (248n - 1n)
32
+ export const maxInt256 = 2n ** (256n - 1n)
33
+
34
+ export const minInt8 = -(2n ** 8n)
35
+ export const minInt16 = -(2n ** 16n)
36
+ export const minInt24 = -(2n ** 24n)
37
+ export const minInt32 = -(2n ** 32n)
38
+ export const minInt40 = -(2n ** 40n)
39
+ export const minInt48 = -(2n ** 48n)
40
+ export const minInt56 = -(2n ** 56n)
41
+ export const minInt64 = -(2n ** 64n)
42
+ export const minInt72 = -(2n ** 72n)
43
+ export const minInt80 = -(2n ** 80n)
44
+ export const minInt88 = -(2n ** 88n)
45
+ export const minInt96 = -(2n ** 96n)
46
+ export const minInt104 = -(2n ** 104n)
47
+ export const minInt112 = -(2n ** 112n)
48
+ export const minInt120 = -(2n ** 120n)
49
+ export const minInt128 = -(2n ** 128n)
50
+ export const minInt136 = -(2n ** 136n)
51
+ export const minInt144 = -(2n ** 144n)
52
+ export const minInt152 = -(2n ** 152n)
53
+ export const minInt160 = -(2n ** 160n)
54
+ export const minInt168 = -(2n ** 168n)
55
+ export const minInt176 = -(2n ** 176n)
56
+ export const minInt184 = -(2n ** 184n)
57
+ export const minInt192 = -(2n ** 192n)
58
+ export const minInt200 = -(2n ** 200n)
59
+ export const minInt208 = -(2n ** 208n)
60
+ export const minInt216 = -(2n ** 216n)
61
+ export const minInt224 = -(2n ** 224n)
62
+ export const minInt232 = -(2n ** 232n)
63
+ export const minInt240 = -(2n ** 240n)
64
+ export const minInt248 = -(2n ** 248n)
65
+ export const minInt256 = -(2n ** 256n)
66
+
67
+ export const maxUint8 = 2n ** 8n
68
+ export const maxUint16 = 2n ** 16n
69
+ export const maxUint24 = 2n ** 24n
70
+ export const maxUint32 = 2n ** 32n
71
+ export const maxUint40 = 2n ** 40n
72
+ export const maxUint48 = 2n ** 48n
73
+ export const maxUint56 = 2n ** 56n
74
+ export const maxUint64 = 2n ** 64n
75
+ export const maxUint72 = 2n ** 72n
76
+ export const maxUint80 = 2n ** 80n
77
+ export const maxUint88 = 2n ** 88n
78
+ export const maxUint96 = 2n ** 96n
79
+ export const maxUint104 = 2n ** 104n
80
+ export const maxUint112 = 2n ** 112n
81
+ export const maxUint120 = 2n ** 120n
82
+ export const maxUint128 = 2n ** 128n
83
+ export const maxUint136 = 2n ** 136n
84
+ export const maxUint144 = 2n ** 144n
85
+ export const maxUint152 = 2n ** 152n
86
+ export const maxUint160 = 2n ** 160n
87
+ export const maxUint168 = 2n ** 168n
88
+ export const maxUint176 = 2n ** 176n
89
+ export const maxUint184 = 2n ** 184n
90
+ export const maxUint192 = 2n ** 192n
91
+ export const maxUint200 = 2n ** 200n
92
+ export const maxUint208 = 2n ** 208n
93
+ export const maxUint216 = 2n ** 216n
94
+ export const maxUint224 = 2n ** 224n
95
+ export const maxUint232 = 2n ** 232n
96
+ export const maxUint240 = 2n ** 240n
97
+ export const maxUint248 = 2n ** 248n
98
+ export const maxUint256 = 2n ** 256n
@@ -1 +1 @@
1
- export const version = '1.4.2'
1
+ export const version = '1.5.0'