viem 0.0.0-main.20230727T170020 → 0.0.0-main.20230730T091111

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 (113) hide show
  1. package/dist/cjs/actions/public/createContractEventFilter.js.map +1 -1
  2. package/dist/cjs/actions/public/createEventFilter.js +2 -0
  3. package/dist/cjs/actions/public/createEventFilter.js.map +1 -1
  4. package/dist/cjs/actions/public/getBlock.js +3 -1
  5. package/dist/cjs/actions/public/getBlock.js.map +1 -1
  6. package/dist/cjs/actions/public/getFilterChanges.js.map +1 -1
  7. package/dist/cjs/actions/public/getFilterLogs.js +1 -1
  8. package/dist/cjs/actions/public/getFilterLogs.js.map +1 -1
  9. package/dist/cjs/actions/public/getLogs.js.map +1 -1
  10. package/dist/cjs/actions/public/getTransaction.js +2 -1
  11. package/dist/cjs/actions/public/getTransaction.js.map +1 -1
  12. package/dist/cjs/actions/public/watchBlocks.js +2 -1
  13. package/dist/cjs/actions/public/watchBlocks.js.map +1 -1
  14. package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
  15. package/dist/cjs/clients/decorators/public.js.map +1 -1
  16. package/dist/cjs/errors/version.js +1 -1
  17. package/dist/cjs/utils/formatters/block.js.map +1 -1
  18. package/dist/cjs/utils/formatters/formatter.js +1 -0
  19. package/dist/cjs/utils/formatters/formatter.js.map +1 -1
  20. package/dist/cjs/utils/formatters/transaction.js.map +1 -1
  21. package/dist/esm/actions/public/createContractEventFilter.js.map +1 -1
  22. package/dist/esm/actions/public/createEventFilter.js +2 -0
  23. package/dist/esm/actions/public/createEventFilter.js.map +1 -1
  24. package/dist/esm/actions/public/getBlock.js +3 -1
  25. package/dist/esm/actions/public/getBlock.js.map +1 -1
  26. package/dist/esm/actions/public/getFilterChanges.js.map +1 -1
  27. package/dist/esm/actions/public/getFilterLogs.js +1 -1
  28. package/dist/esm/actions/public/getFilterLogs.js.map +1 -1
  29. package/dist/esm/actions/public/getLogs.js.map +1 -1
  30. package/dist/esm/actions/public/getTransaction.js +2 -1
  31. package/dist/esm/actions/public/getTransaction.js.map +1 -1
  32. package/dist/esm/actions/public/watchBlocks.js +2 -1
  33. package/dist/esm/actions/public/watchBlocks.js.map +1 -1
  34. package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
  35. package/dist/esm/clients/decorators/public.js.map +1 -1
  36. package/dist/esm/errors/version.js +1 -1
  37. package/dist/esm/utils/formatters/block.js.map +1 -1
  38. package/dist/esm/utils/formatters/formatter.js +1 -0
  39. package/dist/esm/utils/formatters/formatter.js.map +1 -1
  40. package/dist/esm/utils/formatters/transaction.js.map +1 -1
  41. package/dist/types/actions/public/createContractEventFilter.d.ts +5 -5
  42. package/dist/types/actions/public/createContractEventFilter.d.ts.map +1 -1
  43. package/dist/types/actions/public/createEventFilter.d.ts +5 -5
  44. package/dist/types/actions/public/createEventFilter.d.ts.map +1 -1
  45. package/dist/types/actions/public/getBlock.d.ts +5 -5
  46. package/dist/types/actions/public/getBlock.d.ts.map +1 -1
  47. package/dist/types/actions/public/getFilterChanges.d.ts +5 -8
  48. package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
  49. package/dist/types/actions/public/getFilterLogs.d.ts +5 -4
  50. package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
  51. package/dist/types/actions/public/getLogs.d.ts +5 -5
  52. package/dist/types/actions/public/getLogs.d.ts.map +1 -1
  53. package/dist/types/actions/public/getTransaction.d.ts +4 -4
  54. package/dist/types/actions/public/getTransaction.d.ts.map +1 -1
  55. package/dist/types/actions/public/watchBlocks.d.ts +10 -10
  56. package/dist/types/actions/public/watchBlocks.d.ts.map +1 -1
  57. package/dist/types/actions/public/watchContractEvent.d.ts +1 -1
  58. package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
  59. package/dist/types/actions/public/watchEvent.d.ts +1 -1
  60. package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
  61. package/dist/types/chains/formatters/celo.d.ts +4 -0
  62. package/dist/types/chains/formatters/celo.d.ts.map +1 -1
  63. package/dist/types/chains/formatters/optimism.d.ts +5 -3
  64. package/dist/types/chains/formatters/optimism.d.ts.map +1 -1
  65. package/dist/types/chains/index.d.ts +44 -12
  66. package/dist/types/chains/index.d.ts.map +1 -1
  67. package/dist/types/clients/decorators/public.d.ts +9 -8
  68. package/dist/types/clients/decorators/public.d.ts.map +1 -1
  69. package/dist/types/errors/version.d.ts +1 -1
  70. package/dist/types/types/block.d.ts +7 -7
  71. package/dist/types/types/block.d.ts.map +1 -1
  72. package/dist/types/types/filter.d.ts +7 -3
  73. package/dist/types/types/filter.d.ts.map +1 -1
  74. package/dist/types/types/formatter.d.ts +3 -0
  75. package/dist/types/types/formatter.d.ts.map +1 -1
  76. package/dist/types/types/log.d.ts +6 -6
  77. package/dist/types/types/log.d.ts.map +1 -1
  78. package/dist/types/types/rpc.d.ts +3 -3
  79. package/dist/types/types/rpc.d.ts.map +1 -1
  80. package/dist/types/types/transaction.d.ts +8 -8
  81. package/dist/types/types/transaction.d.ts.map +1 -1
  82. package/dist/types/utils/formatters/block.d.ts +13 -3
  83. package/dist/types/utils/formatters/block.d.ts.map +1 -1
  84. package/dist/types/utils/formatters/formatter.d.ts +1 -0
  85. package/dist/types/utils/formatters/formatter.d.ts.map +1 -1
  86. package/dist/types/utils/formatters/transaction.d.ts +10 -3
  87. package/dist/types/utils/formatters/transaction.d.ts.map +1 -1
  88. package/dist/types/utils/formatters/transactionReceipt.d.ts +1 -0
  89. package/dist/types/utils/formatters/transactionReceipt.d.ts.map +1 -1
  90. package/dist/types/utils/formatters/transactionRequest.d.ts +1 -0
  91. package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
  92. package/package.json +1 -1
  93. package/src/actions/public/createContractEventFilter.ts +30 -7
  94. package/src/actions/public/createEventFilter.ts +28 -6
  95. package/src/actions/public/getBlock.ts +18 -8
  96. package/src/actions/public/getFilterChanges.ts +41 -5
  97. package/src/actions/public/getFilterLogs.ts +21 -5
  98. package/src/actions/public/getLogs.ts +20 -6
  99. package/src/actions/public/getTransaction.ts +15 -8
  100. package/src/actions/public/watchBlocks.ts +37 -18
  101. package/src/actions/public/watchContractEvent.ts +5 -5
  102. package/src/actions/public/watchEvent.ts +1 -1
  103. package/src/clients/decorators/public.ts +86 -16
  104. package/src/errors/version.ts +1 -1
  105. package/src/types/block.ts +25 -10
  106. package/src/types/filter.ts +31 -25
  107. package/src/types/formatter.ts +9 -0
  108. package/src/types/log.ts +6 -5
  109. package/src/types/rpc.ts +20 -6
  110. package/src/types/transaction.ts +22 -11
  111. package/src/utils/formatters/block.ts +31 -4
  112. package/src/utils/formatters/formatter.ts +1 -0
  113. package/src/utils/formatters/transaction.ts +25 -2
@@ -6,6 +6,7 @@ import {
6
6
  DecodeLogDataMismatch,
7
7
  DecodeLogTopicsMismatch,
8
8
  } from '../../errors/abi.js'
9
+ import type { BlockNumber, BlockTag } from '../../types/block.js'
9
10
  import type { Chain } from '../../types/chain.js'
10
11
  import type { Filter, FilterType } from '../../types/filter.js'
11
12
  import type { Log } from '../../types/log.js'
@@ -18,8 +19,18 @@ export type GetFilterChangesParameters<
18
19
  TAbi extends Abi | readonly unknown[] = Abi,
19
20
  TEventName extends string | undefined = string,
20
21
  TStrict extends boolean | undefined = undefined,
22
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
23
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
21
24
  > = {
22
- filter: Filter<TFilterType, TAbi, TEventName, any, TStrict>
25
+ filter: Filter<
26
+ TFilterType,
27
+ TAbi,
28
+ TEventName,
29
+ any,
30
+ TStrict,
31
+ TFromBlock,
32
+ TToBlock
33
+ >
23
34
  }
24
35
 
25
36
  export type GetFilterChangesReturnType<
@@ -27,13 +38,18 @@ export type GetFilterChangesReturnType<
27
38
  TAbi extends Abi | readonly unknown[] = Abi,
28
39
  TEventName extends string | undefined = string,
29
40
  TStrict extends boolean | undefined = undefined,
41
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
42
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
30
43
  _AbiEvent extends AbiEvent | undefined = TAbi extends Abi
31
44
  ? TEventName extends string
32
45
  ? ExtractAbiEvent<TAbi, TEventName>
33
46
  : undefined
34
47
  : undefined,
48
+ _Pending extends boolean =
49
+ | (TFromBlock extends 'pending' ? true : false)
50
+ | (TToBlock extends 'pending' ? true : false),
35
51
  > = TFilterType extends 'event'
36
- ? Log<bigint, number, _AbiEvent, TStrict, TAbi, TEventName>[]
52
+ ? Log<bigint, number, _Pending, _AbiEvent, TStrict, TAbi, TEventName>[]
37
53
  : Hash[]
38
54
 
39
55
  /**
@@ -125,12 +141,30 @@ export async function getFilterChanges<
125
141
  TAbi extends Abi | readonly unknown[],
126
142
  TEventName extends string | undefined,
127
143
  TStrict extends boolean | undefined = undefined,
144
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
145
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
128
146
  >(
129
147
  _client: Client<TTransport, TChain>,
130
148
  {
131
149
  filter,
132
- }: GetFilterChangesParameters<TFilterType, TAbi, TEventName, TStrict>,
133
- ) {
150
+ }: GetFilterChangesParameters<
151
+ TFilterType,
152
+ TAbi,
153
+ TEventName,
154
+ TStrict,
155
+ TFromBlock,
156
+ TToBlock
157
+ >,
158
+ ): Promise<
159
+ GetFilterChangesReturnType<
160
+ TFilterType,
161
+ TAbi,
162
+ TEventName,
163
+ TStrict,
164
+ TFromBlock,
165
+ TToBlock
166
+ >
167
+ > {
134
168
  const strict = 'strict' in filter && filter.strict
135
169
 
136
170
  const logs = await filter.request({
@@ -172,6 +206,8 @@ export async function getFilterChanges<
172
206
  TFilterType,
173
207
  TAbi,
174
208
  TEventName,
175
- TStrict
209
+ TStrict,
210
+ TFromBlock,
211
+ TToBlock
176
212
  >
177
213
  }
@@ -6,6 +6,7 @@ import {
6
6
  DecodeLogDataMismatch,
7
7
  DecodeLogTopicsMismatch,
8
8
  } from '../../errors/abi.js'
9
+ import type { BlockNumber, BlockTag } from '../../types/block.js'
9
10
  import type { Chain } from '../../types/chain.js'
10
11
  import type { Filter } from '../../types/filter.js'
11
12
  import type { Log } from '../../types/log.js'
@@ -16,19 +17,26 @@ export type GetFilterLogsParameters<
16
17
  TAbi extends Abi | readonly unknown[] = Abi,
17
18
  TEventName extends string | undefined = string,
18
19
  TStrict extends boolean | undefined = undefined,
20
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
21
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
19
22
  > = {
20
- filter: Filter<'event', TAbi, TEventName, any, TStrict>
23
+ filter: Filter<'event', TAbi, TEventName, any, TStrict, TFromBlock, TToBlock>
21
24
  }
22
25
  export type GetFilterLogsReturnType<
23
26
  TAbi extends Abi | readonly unknown[] = Abi,
24
27
  TEventName extends string | undefined = string,
25
28
  TStrict extends boolean | undefined = undefined,
29
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
30
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
26
31
  _AbiEvent extends AbiEvent | undefined = TAbi extends Abi
27
32
  ? TEventName extends string
28
33
  ? ExtractAbiEvent<TAbi, TEventName>
29
34
  : undefined
30
35
  : undefined,
31
- > = Log<bigint, number, _AbiEvent, TStrict, TAbi, TEventName>[]
36
+ _Pending extends boolean =
37
+ | (TFromBlock extends 'pending' ? true : false)
38
+ | (TToBlock extends 'pending' ? true : false),
39
+ > = Log<bigint, number, _Pending, _AbiEvent, TStrict, TAbi, TEventName>[]
32
40
 
33
41
  /**
34
42
  * Returns a list of event logs since the filter was created.
@@ -62,10 +70,16 @@ export async function getFilterLogs<
62
70
  TAbi extends Abi | readonly unknown[],
63
71
  TEventName extends string | undefined,
64
72
  TStrict extends boolean | undefined = undefined,
73
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
74
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
65
75
  >(
66
76
  _client: Client<Transport, TChain>,
67
- { filter }: GetFilterLogsParameters<TAbi, TEventName, TStrict>,
68
- ): Promise<GetFilterLogsReturnType<TAbi, TEventName, TStrict>> {
77
+ {
78
+ filter,
79
+ }: GetFilterLogsParameters<TAbi, TEventName, TStrict, TFromBlock, TToBlock>,
80
+ ): Promise<
81
+ GetFilterLogsReturnType<TAbi, TEventName, TStrict, TFromBlock, TToBlock>
82
+ > {
69
83
  const strict = filter.strict ?? false
70
84
 
71
85
  const logs = await filter.request({
@@ -105,6 +119,8 @@ export async function getFilterLogs<
105
119
  .filter(Boolean) as unknown as GetFilterLogsReturnType<
106
120
  TAbi,
107
121
  TEventName,
108
- TStrict
122
+ TStrict,
123
+ TFromBlock,
124
+ TToBlock
109
125
  >
110
126
  }
@@ -26,6 +26,8 @@ import { formatLog } from '../../utils/formatters/log.js'
26
26
  export type GetLogsParameters<
27
27
  TAbiEvent extends AbiEvent | undefined = undefined,
28
28
  TStrict extends boolean | undefined = undefined,
29
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
30
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
29
31
  _EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
30
32
  > = {
31
33
  /** Address or list of addresses from which logs originated */
@@ -49,9 +51,9 @@ export type GetLogsParameters<
49
51
  (
50
52
  | {
51
53
  /** Block number or tag after which to include logs */
52
- fromBlock?: BlockNumber<bigint> | BlockTag
54
+ fromBlock?: TFromBlock | BlockNumber | BlockTag
53
55
  /** Block number or tag before which to include logs */
54
- toBlock?: BlockNumber<bigint> | BlockTag
56
+ toBlock?: TToBlock | BlockNumber | BlockTag
55
57
  blockHash?: never
56
58
  }
57
59
  | {
@@ -65,8 +67,13 @@ export type GetLogsParameters<
65
67
  export type GetLogsReturnType<
66
68
  TAbiEvent extends AbiEvent | undefined = undefined,
67
69
  TStrict extends boolean | undefined = undefined,
70
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
71
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
68
72
  _EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
69
- > = Log<bigint, number, TAbiEvent, TStrict, [TAbiEvent], _EventName>[]
73
+ _Pending extends boolean =
74
+ | (TFromBlock extends 'pending' ? true : false)
75
+ | (TToBlock extends 'pending' ? true : false),
76
+ > = Log<bigint, number, _Pending, TAbiEvent, TStrict, [TAbiEvent], _EventName>[]
70
77
 
71
78
  /**
72
79
  * Returns a list of event logs matching the provided parameters.
@@ -94,6 +101,8 @@ export async function getLogs<
94
101
  TChain extends Chain | undefined,
95
102
  TAbiEvent extends AbiEvent | undefined,
96
103
  TStrict extends boolean | undefined = undefined,
104
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
105
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
97
106
  >(
98
107
  client: Client<Transport, TChain>,
99
108
  {
@@ -104,8 +113,8 @@ export async function getLogs<
104
113
  event,
105
114
  args,
106
115
  strict: strict_,
107
- }: GetLogsParameters<TAbiEvent, TStrict> = {},
108
- ): Promise<GetLogsReturnType<TAbiEvent, TStrict>> {
116
+ }: GetLogsParameters<TAbiEvent, TStrict, TFromBlock, TToBlock> = {},
117
+ ): Promise<GetLogsReturnType<TAbiEvent, TStrict, TFromBlock, TToBlock>> {
109
118
  const strict = strict_ ?? false
110
119
 
111
120
  let topics: LogTopic[] = []
@@ -166,5 +175,10 @@ export async function getLogs<
166
175
  return formatLog(log, { args: isUnnamed ? [] : {}, eventName })
167
176
  }
168
177
  })
169
- .filter(Boolean) as unknown as GetLogsReturnType<TAbiEvent, TStrict>
178
+ .filter(Boolean) as unknown as GetLogsReturnType<
179
+ TAbiEvent,
180
+ TStrict,
181
+ TFromBlock,
182
+ TToBlock
183
+ >
170
184
  }
@@ -11,7 +11,7 @@ import {
11
11
  formatTransaction,
12
12
  } from '../../utils/formatters/transaction.js'
13
13
 
14
- export type GetTransactionParameters =
14
+ export type GetTransactionParameters<TBlockTag extends BlockTag = 'latest'> =
15
15
  | {
16
16
  /** The block hash */
17
17
  blockHash: Hash
@@ -34,7 +34,7 @@ export type GetTransactionParameters =
34
34
  blockHash?: never
35
35
  blockNumber?: never
36
36
  /** The block tag. */
37
- blockTag: BlockTag
37
+ blockTag: TBlockTag | BlockTag
38
38
  hash?: never
39
39
  /** The index of the transaction on the block. */
40
40
  index: number
@@ -48,8 +48,10 @@ export type GetTransactionParameters =
48
48
  index?: number
49
49
  }
50
50
 
51
- export type GetTransactionReturnType<TChain extends Chain | undefined = Chain> =
52
- FormattedTransaction<TChain>
51
+ export type GetTransactionReturnType<
52
+ TChain extends Chain | undefined = Chain,
53
+ TBlockTag extends BlockTag = 'latest',
54
+ > = FormattedTransaction<TChain, TBlockTag>
53
55
 
54
56
  /**
55
57
  * Returns information about a [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) given a hash or block identifier.
@@ -75,16 +77,21 @@ export type GetTransactionReturnType<TChain extends Chain | undefined = Chain> =
75
77
  * hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
76
78
  * })
77
79
  */
78
- export async function getTransaction<TChain extends Chain | undefined>(
80
+ export async function getTransaction<
81
+ TChain extends Chain | undefined,
82
+ TBlockTag extends BlockTag = 'latest',
83
+ >(
79
84
  client: Client<Transport, TChain>,
80
85
  {
81
86
  blockHash,
82
87
  blockNumber,
83
- blockTag = 'latest',
88
+ blockTag: blockTag_,
84
89
  hash,
85
90
  index,
86
- }: GetTransactionParameters,
87
- ): Promise<GetTransactionReturnType<TChain>> {
91
+ }: GetTransactionParameters<TBlockTag>,
92
+ ): Promise<GetTransactionReturnType<TChain, TBlockTag>> {
93
+ const blockTag = blockTag_ || 'latest'
94
+
88
95
  const blockNumberHex =
89
96
  blockNumber !== undefined ? numberToHex(blockNumber) : undefined
90
97
 
@@ -10,23 +10,35 @@ import { stringify } from '../../utils/stringify.js'
10
10
 
11
11
  import { type GetBlockReturnType, getBlock } from './getBlock.js'
12
12
 
13
- export type OnBlockParameter<TChain extends Chain | undefined = Chain> =
14
- GetBlockReturnType<TChain>
13
+ export type OnBlockParameter<
14
+ TChain extends Chain | undefined = Chain,
15
+ TIncludeTransactions extends boolean = false,
16
+ TBlockTag extends BlockTag = 'latest',
17
+ > = GetBlockReturnType<TChain, TIncludeTransactions, TBlockTag>
15
18
 
16
- export type OnBlock<TChain extends Chain | undefined = Chain> = (
17
- block: OnBlockParameter<TChain>,
18
- prevBlock: OnBlockParameter<TChain> | undefined,
19
+ export type OnBlock<
20
+ TChain extends Chain | undefined = Chain,
21
+ TIncludeTransactions extends boolean = false,
22
+ TBlockTag extends BlockTag = 'latest',
23
+ > = (
24
+ block: OnBlockParameter<TChain, TIncludeTransactions, TBlockTag>,
25
+ prevBlock:
26
+ | OnBlockParameter<TChain, TIncludeTransactions, TBlockTag>
27
+ | undefined,
19
28
  ) => void
20
29
 
21
- type PollOptions = {
30
+ type PollOptions<
31
+ TIncludeTransactions extends boolean = false,
32
+ TBlockTag extends BlockTag = 'latest',
33
+ > = {
22
34
  /** The block tag. Defaults to "latest". */
23
- blockTag?: BlockTag
35
+ blockTag?: TBlockTag | BlockTag
24
36
  /** Whether or not to emit the missed blocks to the callback. */
25
37
  emitMissed?: boolean
26
38
  /** Whether or not to emit the block to the callback when the subscription opens. */
27
39
  emitOnBegin?: boolean
28
40
  /** Whether or not to include transaction data in the response. */
29
- includeTransactions?: boolean
41
+ includeTransactions?: TIncludeTransactions
30
42
  /** Polling frequency (in ms). Defaults to the client's pollingInterval config. */
31
43
  pollingInterval?: number
32
44
  }
@@ -34,9 +46,11 @@ type PollOptions = {
34
46
  export type WatchBlocksParameters<
35
47
  TTransport extends Transport = Transport,
36
48
  TChain extends Chain | undefined = Chain,
49
+ TIncludeTransactions extends boolean = false,
50
+ TBlockTag extends BlockTag = 'latest',
37
51
  > = {
38
52
  /** The callback to call when a new block is received. */
39
- onBlock: OnBlock<TChain>
53
+ onBlock: OnBlock<TChain, TIncludeTransactions, TBlockTag>
40
54
  /** The callback to call when an error occurred when trying to get for a new block. */
41
55
  onError?: (error: Error) => void
42
56
  } & (GetTransportConfig<TTransport>['type'] extends 'webSocket'
@@ -50,8 +64,8 @@ export type WatchBlocksParameters<
50
64
  poll?: false
51
65
  pollingInterval?: never
52
66
  }
53
- | (PollOptions & { poll?: true })
54
- : PollOptions & { poll?: true })
67
+ | (PollOptions<TIncludeTransactions, TBlockTag> & { poll?: true })
68
+ : PollOptions<TIncludeTransactions, TBlockTag> & { poll?: true })
55
69
 
56
70
  export type WatchBlocksReturnType = () => void
57
71
 
@@ -83,6 +97,8 @@ export type WatchBlocksReturnType = () => void
83
97
  export function watchBlocks<
84
98
  TTransport extends Transport,
85
99
  TChain extends Chain | undefined,
100
+ TIncludeTransactions extends boolean = false,
101
+ TBlockTag extends BlockTag = 'latest',
86
102
  >(
87
103
  client: Client<TTransport, TChain>,
88
104
  {
@@ -91,15 +107,18 @@ export function watchBlocks<
91
107
  emitOnBegin = false,
92
108
  onBlock,
93
109
  onError,
94
- includeTransactions = false,
110
+ includeTransactions: includeTransactions_,
95
111
  poll: poll_,
96
112
  pollingInterval = client.pollingInterval,
97
- }: WatchBlocksParameters<TTransport, TChain>,
113
+ }: WatchBlocksParameters<TTransport, TChain, TIncludeTransactions, TBlockTag>,
98
114
  ): WatchBlocksReturnType {
99
115
  const enablePolling =
100
116
  typeof poll_ !== 'undefined' ? poll_ : client.transport.type !== 'webSocket'
117
+ const includeTransactions = includeTransactions_ ?? false
101
118
 
102
- let prevBlock: GetBlockReturnType<TChain> | undefined
119
+ let prevBlock:
120
+ | GetBlockReturnType<TChain, false | TIncludeTransactions, 'latest'>
121
+ | undefined
103
122
 
104
123
  const pollBlocks = () => {
105
124
  const observerId = stringify([
@@ -132,7 +151,7 @@ export function watchBlocks<
132
151
  blockNumber: i,
133
152
  includeTransactions,
134
153
  })
135
- emit.onBlock(block, prevBlock)
154
+ emit.onBlock(block as any, prevBlock as any)
136
155
  prevBlock = block
137
156
  }
138
157
  }
@@ -147,8 +166,8 @@ export function watchBlocks<
147
166
  // We don't want to emit blocks in the past.
148
167
  (block.number && block.number > prevBlock.number)
149
168
  ) {
150
- emit.onBlock(block, prevBlock)
151
- prevBlock = block
169
+ emit.onBlock(block as any, prevBlock as any)
170
+ prevBlock = block as any
152
171
  }
153
172
  } catch (err) {
154
173
  emit.onError?.(err as Error)
@@ -174,7 +193,7 @@ export function watchBlocks<
174
193
  const format =
175
194
  client.chain?.formatters?.block?.format || formatBlock
176
195
  const block = format(data.result)
177
- onBlock(block, prevBlock)
196
+ onBlock(block, prevBlock as any)
178
197
  prevBlock = block
179
198
  },
180
199
  onError(error: Error) {
@@ -1,4 +1,4 @@
1
- import type { Abi, Address, ExtractAbiEvent, Narrow } from 'abitype'
1
+ import type { Abi, AbiEvent, Address, ExtractAbiEvent, Narrow } from 'abitype'
2
2
 
3
3
  import type { Client } from '../../clients/createClient.js'
4
4
  import type { Transport } from '../../clients/transports/createTransport.js'
@@ -20,7 +20,7 @@ import {
20
20
  } from './createContractEventFilter.js'
21
21
  import { getBlockNumber } from './getBlockNumber.js'
22
22
  import { getFilterChanges } from './getFilterChanges.js'
23
- import { type GetLogsParameters, getLogs } from './getLogs.js'
23
+ import { getLogs } from './getLogs.js'
24
24
  import { uninstallFilter } from './uninstallFilter.js'
25
25
 
26
26
  export type WatchContractEventOnLogsParameter<
@@ -28,7 +28,7 @@ export type WatchContractEventOnLogsParameter<
28
28
  TEventName extends string = string,
29
29
  TStrict extends boolean | undefined = undefined,
30
30
  > = TAbi extends Abi
31
- ? Log<bigint, number, ExtractAbiEvent<TAbi, TEventName>, TStrict>[]
31
+ ? Log<bigint, number, false, ExtractAbiEvent<TAbi, TEventName>, TStrict>[]
32
32
  : Log[]
33
33
  export type WatchContractEventOnLogsFn<
34
34
  TAbi extends Abi | readonly unknown[] = readonly unknown[],
@@ -173,8 +173,8 @@ export function watchContractEvent<
173
173
  event: getAbiItem({
174
174
  abi,
175
175
  name: eventName,
176
- } as unknown as GetAbiItemParameters),
177
- } as unknown as GetLogsParameters)
176
+ } as unknown as GetAbiItemParameters) as AbiEvent,
177
+ })
178
178
  } else {
179
179
  logs = []
180
180
  }
@@ -26,7 +26,7 @@ export type WatchEventOnLogsParameter<
26
26
  TAbiEvent extends AbiEvent | undefined = undefined,
27
27
  TStrict extends boolean | undefined = undefined,
28
28
  TEventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
29
- > = Log<bigint, number, TAbiEvent, TStrict, [TAbiEvent], TEventName>[]
29
+ > = Log<bigint, number, false, TAbiEvent, TStrict, [TAbiEvent], TEventName>[]
30
30
  export type WatchEventOnLogsFn<
31
31
  TAbiEvent extends AbiEvent | undefined = undefined,
32
32
  TStrict extends boolean | undefined = undefined,
@@ -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).
@@ -310,6 +327,8 @@ export type PublicActions<
310
327
  createEventFilter: <
311
328
  TAbiEvent extends AbiEvent | undefined,
312
329
  TStrict extends boolean | undefined = undefined,
330
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
331
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
313
332
  _Abi extends Abi | readonly unknown[] = [TAbiEvent],
314
333
  _EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
315
334
  _Args extends
@@ -319,12 +338,22 @@ export type PublicActions<
319
338
  args?: CreateEventFilterParameters<
320
339
  TAbiEvent,
321
340
  TStrict,
341
+ TFromBlock,
342
+ TToBlock,
322
343
  _Abi,
323
344
  _EventName,
324
345
  _Args
325
346
  >,
326
347
  ) => Promise<
327
- CreateEventFilterReturnType<TAbiEvent, TStrict, _Abi, _EventName, _Args>
348
+ CreateEventFilterReturnType<
349
+ TAbiEvent,
350
+ TStrict,
351
+ TFromBlock,
352
+ TToBlock,
353
+ _Abi,
354
+ _EventName,
355
+ _Args
356
+ >
328
357
  >
329
358
  /**
330
359
  * 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 +491,12 @@ export type PublicActions<
462
491
  * })
463
492
  * const block = await client.getBlock()
464
493
  */
465
- getBlock: (args?: GetBlockParameters) => Promise<GetBlockReturnType<TChain>>
494
+ getBlock: <
495
+ TIncludeTransactions extends boolean = false,
496
+ TBlockTag extends BlockTag = 'latest',
497
+ >(
498
+ args?: GetBlockParameters<TIncludeTransactions, TBlockTag>,
499
+ ) => Promise<GetBlockReturnType<TChain, TIncludeTransactions, TBlockTag>>
466
500
  /**
467
501
  * Returns the number of the most recent block seen.
468
502
  *
@@ -810,10 +844,26 @@ export type PublicActions<
810
844
  TAbi extends Abi | readonly unknown[],
811
845
  TEventName extends string | undefined,
812
846
  TStrict extends boolean | undefined = undefined,
847
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
848
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
813
849
  >(
814
- args: GetFilterChangesParameters<TFilterType, TAbi, TEventName, TStrict>,
850
+ args: GetFilterChangesParameters<
851
+ TFilterType,
852
+ TAbi,
853
+ TEventName,
854
+ TStrict,
855
+ TFromBlock,
856
+ TToBlock
857
+ >,
815
858
  ) => Promise<
816
- GetFilterChangesReturnType<TFilterType, TAbi, TEventName, TStrict>
859
+ GetFilterChangesReturnType<
860
+ TFilterType,
861
+ TAbi,
862
+ TEventName,
863
+ TStrict,
864
+ TFromBlock,
865
+ TToBlock
866
+ >
817
867
  >
818
868
  /**
819
869
  * Returns a list of event logs since the filter was created.
@@ -845,9 +895,19 @@ export type PublicActions<
845
895
  TAbi extends Abi | readonly unknown[],
846
896
  TEventName extends string | undefined,
847
897
  TStrict extends boolean | undefined = undefined,
898
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
899
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
848
900
  >(
849
- args: GetFilterLogsParameters<TAbi, TEventName, TStrict>,
850
- ) => Promise<GetFilterLogsReturnType<TAbi, TEventName, TStrict>>
901
+ args: GetFilterLogsParameters<
902
+ TAbi,
903
+ TEventName,
904
+ TStrict,
905
+ TFromBlock,
906
+ TToBlock
907
+ >,
908
+ ) => Promise<
909
+ GetFilterLogsReturnType<TAbi, TEventName, TStrict, TFromBlock, TToBlock>
910
+ >
851
911
  /**
852
912
  * Returns the current price of gas (in wei).
853
913
  *
@@ -890,9 +950,11 @@ export type PublicActions<
890
950
  getLogs: <
891
951
  TAbiEvent extends AbiEvent | undefined,
892
952
  TStrict extends boolean | undefined = undefined,
953
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
954
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
893
955
  >(
894
- args?: GetLogsParameters<TAbiEvent, TStrict>,
895
- ) => Promise<GetLogsReturnType<TAbiEvent, TStrict>>
956
+ args?: GetLogsParameters<TAbiEvent, TStrict, TFromBlock, TToBlock>,
957
+ ) => Promise<GetLogsReturnType<TAbiEvent, TStrict, TFromBlock, TToBlock>>
896
958
  /**
897
959
  * Returns the value from a storage slot at a given address.
898
960
  *
@@ -941,9 +1003,9 @@ export type PublicActions<
941
1003
  * hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
942
1004
  * })
943
1005
  */
944
- getTransaction: (
945
- args: GetTransactionParameters,
946
- ) => Promise<GetTransactionReturnType<TChain>>
1006
+ getTransaction: <TBlockTag extends BlockTag = 'latest'>(
1007
+ args: GetTransactionParameters<TBlockTag>,
1008
+ ) => Promise<GetTransactionReturnType<TChain, TBlockTag>>
947
1009
  /**
948
1010
  * Returns the number of blocks passed (confirmations) since the transaction was processed on a block.
949
1011
  *
@@ -1265,8 +1327,16 @@ export type PublicActions<
1265
1327
  * onBlock: (block) => console.log(block),
1266
1328
  * })
1267
1329
  */
1268
- watchBlocks: (
1269
- args: WatchBlocksParameters<TTransport, TChain>,
1330
+ watchBlocks: <
1331
+ TIncludeTransactions extends boolean = false,
1332
+ TBlockTag extends BlockTag = 'latest',
1333
+ >(
1334
+ args: WatchBlocksParameters<
1335
+ TTransport,
1336
+ TChain,
1337
+ TIncludeTransactions,
1338
+ TBlockTag
1339
+ >,
1270
1340
  ) => WatchBlocksReturnType
1271
1341
  /**
1272
1342
  * Watches and returns emitted contract event logs.
@@ -1406,7 +1476,7 @@ export function publicActions<
1406
1476
  getFilterChanges: (args) => getFilterChanges(client, args),
1407
1477
  getFilterLogs: (args) => getFilterLogs(client, args),
1408
1478
  getGasPrice: () => getGasPrice(client),
1409
- getLogs: (args) => getLogs(client, args),
1479
+ getLogs: (args) => getLogs(client, args as any),
1410
1480
  getStorageAt: (args) => getStorageAt(client, args),
1411
1481
  getTransaction: (args) => getTransaction(client, args),
1412
1482
  getTransactionConfirmations: (args) =>
@@ -1 +1 @@
1
- export const version = '0.0.0-main.20230727T170020'
1
+ export const version = '0.0.0-main.20230730T091111'