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

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 (122) hide show
  1. package/dist/cjs/actions/public/createContractEventFilter.js.map +1 -1
  2. package/dist/cjs/actions/public/createEventFilter.js +16 -8
  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 +16 -10
  10. package/dist/cjs/actions/public/getLogs.js.map +1 -1
  11. package/dist/cjs/actions/public/getTransaction.js +2 -1
  12. package/dist/cjs/actions/public/getTransaction.js.map +1 -1
  13. package/dist/cjs/actions/public/watchBlocks.js +2 -1
  14. package/dist/cjs/actions/public/watchBlocks.js.map +1 -1
  15. package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
  16. package/dist/cjs/actions/public/watchEvent.js +4 -2
  17. package/dist/cjs/actions/public/watchEvent.js.map +1 -1
  18. package/dist/cjs/clients/decorators/public.js.map +1 -1
  19. package/dist/cjs/errors/version.js +1 -1
  20. package/dist/cjs/utils/formatters/block.js.map +1 -1
  21. package/dist/cjs/utils/formatters/formatter.js +1 -0
  22. package/dist/cjs/utils/formatters/formatter.js.map +1 -1
  23. package/dist/cjs/utils/formatters/transaction.js.map +1 -1
  24. package/dist/esm/actions/public/createContractEventFilter.js.map +1 -1
  25. package/dist/esm/actions/public/createEventFilter.js +16 -8
  26. package/dist/esm/actions/public/createEventFilter.js.map +1 -1
  27. package/dist/esm/actions/public/getBlock.js +3 -1
  28. package/dist/esm/actions/public/getBlock.js.map +1 -1
  29. package/dist/esm/actions/public/getFilterChanges.js.map +1 -1
  30. package/dist/esm/actions/public/getFilterLogs.js +1 -1
  31. package/dist/esm/actions/public/getFilterLogs.js.map +1 -1
  32. package/dist/esm/actions/public/getLogs.js +16 -10
  33. package/dist/esm/actions/public/getLogs.js.map +1 -1
  34. package/dist/esm/actions/public/getTransaction.js +2 -1
  35. package/dist/esm/actions/public/getTransaction.js.map +1 -1
  36. package/dist/esm/actions/public/watchBlocks.js +2 -1
  37. package/dist/esm/actions/public/watchBlocks.js.map +1 -1
  38. package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
  39. package/dist/esm/actions/public/watchEvent.js +4 -2
  40. package/dist/esm/actions/public/watchEvent.js.map +1 -1
  41. package/dist/esm/clients/decorators/public.js.map +1 -1
  42. package/dist/esm/errors/version.js +1 -1
  43. package/dist/esm/utils/formatters/block.js.map +1 -1
  44. package/dist/esm/utils/formatters/formatter.js +1 -0
  45. package/dist/esm/utils/formatters/formatter.js.map +1 -1
  46. package/dist/esm/utils/formatters/transaction.js.map +1 -1
  47. package/dist/types/actions/public/createContractEventFilter.d.ts +5 -5
  48. package/dist/types/actions/public/createContractEventFilter.d.ts.map +1 -1
  49. package/dist/types/actions/public/createEventFilter.d.ts +20 -7
  50. package/dist/types/actions/public/createEventFilter.d.ts.map +1 -1
  51. package/dist/types/actions/public/getBlock.d.ts +5 -5
  52. package/dist/types/actions/public/getBlock.d.ts.map +1 -1
  53. package/dist/types/actions/public/getFilterChanges.d.ts +5 -8
  54. package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
  55. package/dist/types/actions/public/getFilterLogs.d.ts +5 -4
  56. package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
  57. package/dist/types/actions/public/getLogs.d.ts +17 -6
  58. package/dist/types/actions/public/getLogs.d.ts.map +1 -1
  59. package/dist/types/actions/public/getTransaction.d.ts +4 -4
  60. package/dist/types/actions/public/getTransaction.d.ts.map +1 -1
  61. package/dist/types/actions/public/watchBlocks.d.ts +10 -10
  62. package/dist/types/actions/public/watchBlocks.d.ts.map +1 -1
  63. package/dist/types/actions/public/watchContractEvent.d.ts +1 -1
  64. package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
  65. package/dist/types/actions/public/watchEvent.d.ts +19 -8
  66. package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
  67. package/dist/types/chains/formatters/celo.d.ts +4 -0
  68. package/dist/types/chains/formatters/celo.d.ts.map +1 -1
  69. package/dist/types/chains/formatters/optimism.d.ts +5 -3
  70. package/dist/types/chains/formatters/optimism.d.ts.map +1 -1
  71. package/dist/types/chains/index.d.ts +44 -12
  72. package/dist/types/chains/index.d.ts.map +1 -1
  73. package/dist/types/clients/decorators/public.d.ts +10 -9
  74. package/dist/types/clients/decorators/public.d.ts.map +1 -1
  75. package/dist/types/errors/version.d.ts +1 -1
  76. package/dist/types/types/block.d.ts +7 -7
  77. package/dist/types/types/block.d.ts.map +1 -1
  78. package/dist/types/types/contract.d.ts +1 -1
  79. package/dist/types/types/contract.d.ts.map +1 -1
  80. package/dist/types/types/filter.d.ts +7 -3
  81. package/dist/types/types/filter.d.ts.map +1 -1
  82. package/dist/types/types/formatter.d.ts +3 -0
  83. package/dist/types/types/formatter.d.ts.map +1 -1
  84. package/dist/types/types/log.d.ts +8 -8
  85. package/dist/types/types/log.d.ts.map +1 -1
  86. package/dist/types/types/rpc.d.ts +3 -3
  87. package/dist/types/types/rpc.d.ts.map +1 -1
  88. package/dist/types/types/transaction.d.ts +8 -8
  89. package/dist/types/types/transaction.d.ts.map +1 -1
  90. package/dist/types/utils/formatters/block.d.ts +13 -3
  91. package/dist/types/utils/formatters/block.d.ts.map +1 -1
  92. package/dist/types/utils/formatters/formatter.d.ts +1 -0
  93. package/dist/types/utils/formatters/formatter.d.ts.map +1 -1
  94. package/dist/types/utils/formatters/transaction.d.ts +10 -3
  95. package/dist/types/utils/formatters/transaction.d.ts.map +1 -1
  96. package/dist/types/utils/formatters/transactionReceipt.d.ts +1 -0
  97. package/dist/types/utils/formatters/transactionReceipt.d.ts.map +1 -1
  98. package/dist/types/utils/formatters/transactionRequest.d.ts +1 -0
  99. package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
  100. package/package.json +1 -1
  101. package/src/actions/public/createContractEventFilter.ts +30 -7
  102. package/src/actions/public/createEventFilter.ts +78 -24
  103. package/src/actions/public/getBlock.ts +18 -8
  104. package/src/actions/public/getFilterChanges.ts +46 -10
  105. package/src/actions/public/getFilterLogs.ts +26 -10
  106. package/src/actions/public/getLogs.ts +73 -18
  107. package/src/actions/public/getTransaction.ts +15 -8
  108. package/src/actions/public/watchBlocks.ts +37 -18
  109. package/src/actions/public/watchContractEvent.ts +5 -5
  110. package/src/actions/public/watchEvent.ts +50 -17
  111. package/src/clients/decorators/public.ts +114 -25
  112. package/src/errors/version.ts +1 -1
  113. package/src/types/block.ts +25 -10
  114. package/src/types/contract.ts +7 -3
  115. package/src/types/filter.ts +32 -26
  116. package/src/types/formatter.ts +9 -0
  117. package/src/types/log.ts +13 -8
  118. package/src/types/rpc.ts +20 -6
  119. package/src/types/transaction.ts +22 -11
  120. package/src/utils/formatters/block.ts +31 -4
  121. package/src/utils/formatters/formatter.ts +1 -0
  122. package/src/utils/formatters/transaction.ts +25 -2
@@ -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) =>
@@ -1 +1 @@
1
- export const version = '0.0.0-main.20230727T170020'
1
+ export const version = '0.0.0-main.20230730T155828'
@@ -3,7 +3,16 @@ import type { Address } from 'abitype'
3
3
  import type { Hash, Hex } from './misc.js'
4
4
  import type { Transaction } from './transaction.js'
5
5
 
6
- export type Block<TQuantity = bigint, TTransaction = Transaction> = {
6
+ export type Block<
7
+ TQuantity = bigint,
8
+ TIncludeTransactions extends boolean = boolean,
9
+ TBlockTag extends BlockTag = BlockTag,
10
+ TTransaction = Transaction<
11
+ bigint,
12
+ number,
13
+ TBlockTag extends 'pending' ? true : false
14
+ >,
15
+ > = {
7
16
  /** Base fee per gas */
8
17
  baseFeePerGas: TQuantity | null
9
18
  /** Difficulty for this block */
@@ -15,17 +24,17 @@ export type Block<TQuantity = bigint, TTransaction = Transaction> = {
15
24
  /** Total used gas by all transactions in this block */
16
25
  gasUsed: TQuantity
17
26
  /** Block hash or `null` if pending */
18
- hash: Hash | null
27
+ hash: TBlockTag extends 'pending' ? null : Hash
19
28
  /** Logs bloom filter or `null` if pending */
20
- logsBloom: Hex | null
29
+ logsBloom: TBlockTag extends 'pending' ? null : Hex
21
30
  /** Address that received this block’s mining rewards */
22
31
  miner: Address
23
32
  /** Unique identifier for the block. */
24
33
  mixHash: Hash
25
34
  /** Proof-of-work hash or `null` if pending */
26
- nonce: Hex | null
35
+ nonce: TBlockTag extends 'pending' ? null : Hex
27
36
  /** Block number or `null` if pending */
28
- number: TQuantity | null
37
+ number: TBlockTag extends 'pending' ? null : TQuantity
29
38
  /** Parent block hash */
30
39
  parentHash: Hash
31
40
  /** Root of the this block’s receipts trie */
@@ -42,7 +51,7 @@ export type Block<TQuantity = bigint, TTransaction = Transaction> = {
42
51
  /** Total difficulty of the chain until this block */
43
52
  totalDifficulty: TQuantity | null
44
53
  /** List of transaction objects or hashes */
45
- transactions: Hash[] | TTransaction[]
54
+ transactions: TIncludeTransactions extends true ? TTransaction[] : Hash[]
46
55
  /** Root of this block’s transaction trie */
47
56
  transactionsRoot: Hash
48
57
  /** List of uncle hashes */
@@ -67,7 +76,13 @@ export type BlockNumber<TQuantity = bigint> = TQuantity
67
76
 
68
77
  export type BlockTag = 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'
69
78
 
70
- export type Uncle<TQuantity = bigint, TTransaction = Transaction> = Block<
71
- TQuantity,
72
- TTransaction
73
- >
79
+ export type Uncle<
80
+ TQuantity = bigint,
81
+ TIncludeTransactions extends boolean = boolean,
82
+ TBlockTag extends BlockTag = BlockTag,
83
+ TTransaction = Transaction<
84
+ bigint,
85
+ number,
86
+ TBlockTag extends 'pending' ? true : false
87
+ >,
88
+ > = Block<TQuantity, TIncludeTransactions, TBlockTag, TTransaction>
@@ -83,9 +83,13 @@ export type MaybeAbiEventName<TAbiEvent extends AbiEvent | undefined> =
83
83
  TAbiEvent extends AbiEvent ? TAbiEvent['name'] : undefined
84
84
 
85
85
  export type MaybeExtractEventArgsFromAbi<
86
- TAbi extends Abi | readonly unknown[] = Abi,
87
- TEventName extends string | undefined = undefined,
88
- > = TEventName extends string ? GetEventArgs<TAbi, TEventName> : undefined
86
+ TAbi extends Abi | readonly unknown[] | undefined,
87
+ TEventName extends string | undefined,
88
+ > = TAbi extends Abi | readonly unknown[]
89
+ ? TEventName extends string
90
+ ? GetEventArgs<TAbi, TEventName>
91
+ : undefined
92
+ : undefined
89
93
 
90
94
  //////////////////////////////////////////////////////////////////////
91
95
  // ABI item name
@@ -1,5 +1,6 @@
1
1
  import type { Abi } from 'abitype'
2
2
 
3
+ import type { BlockNumber, BlockTag } from './block.js'
3
4
  import type { MaybeExtractEventArgsFromAbi } from './contract.js'
4
5
  import type { EIP1193RequestFn, PublicRpcSchema } from './eip1193.js'
5
6
  import type { Hex } from './misc.js'
@@ -16,42 +17,47 @@ type FilterRpcSchema = Filter_<
16
17
 
17
18
  export type Filter<
18
19
  TFilterType extends FilterType = 'event',
19
- TAbi extends Abi | readonly unknown[] = Abi,
20
+ TAbi extends Abi | readonly unknown[] | undefined = undefined,
20
21
  TEventName extends string | undefined = undefined,
21
22
  TArgs extends
22
23
  | MaybeExtractEventArgsFromAbi<TAbi, TEventName>
23
24
  | undefined = MaybeExtractEventArgsFromAbi<TAbi, TEventName>,
24
25
  TStrict extends boolean | undefined = undefined,
26
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
27
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
25
28
  > = {
26
29
  id: Hex
27
30
  request: EIP1193RequestFn<FilterRpcSchema>
28
31
  type: TFilterType
29
32
  } & (TFilterType extends 'event'
30
- ? TAbi extends Abi
31
- ? undefined extends TEventName
32
- ? {
33
- abi: TAbi
34
- args?: never
35
- eventName?: never
36
- strict: TStrict
37
- }
38
- : TArgs extends MaybeExtractEventArgsFromAbi<TAbi, TEventName>
39
- ? {
40
- abi: TAbi
41
- args: TArgs
42
- eventName: TEventName
43
- strict: TStrict
44
- }
33
+ ? {
34
+ fromBlock?: TFromBlock
35
+ toBlock?: TToBlock
36
+ } & (TAbi extends Abi
37
+ ? undefined extends TEventName
38
+ ? {
39
+ abi: TAbi
40
+ args?: never
41
+ eventName?: never
42
+ strict: TStrict
43
+ }
44
+ : TArgs extends MaybeExtractEventArgsFromAbi<TAbi, TEventName>
45
+ ? {
46
+ abi: TAbi
47
+ args: TArgs
48
+ eventName: TEventName
49
+ strict: TStrict
50
+ }
51
+ : {
52
+ abi: TAbi
53
+ args?: never
54
+ eventName: TEventName
55
+ strict: TStrict
56
+ }
45
57
  : {
46
- abi: TAbi
58
+ abi?: never
47
59
  args?: never
48
- eventName: TEventName
49
- strict: TStrict
50
- }
51
- : {
52
- abi?: never
53
- args?: never
54
- eventName?: never
55
- strict?: never
56
- }
60
+ eventName?: never
61
+ strict?: never
62
+ })
57
63
  : {})
@@ -12,6 +12,15 @@ export type Formatters = {
12
12
  transactionRequest?: Formatter<'transactionRequest'>
13
13
  }
14
14
 
15
+ export type ExtractFormatterExclude<
16
+ TChain extends Chain | undefined,
17
+ TType extends keyof Formatters,
18
+ > = TChain extends Chain<infer _Formatters extends Formatters>
19
+ ? _Formatters[TType] extends { exclude: infer Exclude }
20
+ ? Extract<Exclude, string[]>[number]
21
+ : ''
22
+ : ''
23
+
15
24
  export type ExtractFormatterParameters<
16
25
  TChain extends Chain | undefined,
17
26
  TType extends keyof Formatters,
package/src/types/log.ts CHANGED
@@ -15,9 +15,12 @@ import type { Hash, Hex } from './misc.js'
15
15
  export type Log<
16
16
  TQuantity = bigint,
17
17
  TIndex = number,
18
+ TPending extends boolean = boolean,
18
19
  TAbiEvent extends AbiEvent | undefined = undefined,
19
20
  TStrict extends boolean | undefined = undefined,
20
- TAbi extends Abi | readonly unknown[] = [TAbiEvent],
21
+ TAbi extends Abi | readonly unknown[] | undefined = TAbiEvent extends AbiEvent
22
+ ? [TAbiEvent]
23
+ : undefined,
21
24
  TEventName extends string | undefined = TAbiEvent extends AbiEvent
22
25
  ? TAbiEvent['name']
23
26
  : undefined,
@@ -25,17 +28,17 @@ export type Log<
25
28
  /** The address from which this log originated */
26
29
  address: Address
27
30
  /** Hash of block containing this log or `null` if pending */
28
- blockHash: Hash | null
31
+ blockHash: TPending extends true ? null : Hash
29
32
  /** Number of block containing this log or `null` if pending */
30
- blockNumber: TQuantity | null
33
+ blockNumber: TPending extends true ? null : TQuantity
31
34
  /** Contains the non-indexed arguments of the log */
32
35
  data: Hex
33
36
  /** Index of this log within its block or `null` if pending */
34
- logIndex: TIndex | null
37
+ logIndex: TPending extends true ? null : TIndex
35
38
  /** Hash of the transaction that created this log or `null` if pending */
36
- transactionHash: Hash | null
39
+ transactionHash: TPending extends true ? null : Hash
37
40
  /** Index of the transaction that created this log or `null` if pending */
38
- transactionIndex: TIndex | null
41
+ transactionIndex: TPending extends true ? null : TIndex
39
42
  /** `true` if this filter has been destroyed and is invalid */
40
43
  removed: boolean
41
44
  } & GetInferredLogValues<TAbiEvent, TAbi, TEventName, TStrict>
@@ -79,7 +82,9 @@ type GetTopics<
79
82
 
80
83
  type GetInferredLogValues<
81
84
  TAbiEvent extends AbiEvent | undefined = undefined,
82
- TAbi extends Abi | readonly unknown[] = [TAbiEvent],
85
+ TAbi extends Abi | readonly unknown[] | undefined = TAbiEvent extends AbiEvent
86
+ ? [TAbiEvent]
87
+ : undefined,
83
88
  TEventName extends string | undefined = TAbiEvent extends AbiEvent
84
89
  ? TAbiEvent['name']
85
90
  : undefined,
@@ -110,7 +115,7 @@ type GetInferredLogValues<
110
115
  [TName in _EventNames]: {
111
116
  args: GetEventArgs<
112
117
  TAbi,
113
- string,
118
+ TName,
114
119
  {
115
120
  EnableUnion: false
116
121
  IndexedOnly: false
package/src/types/rpc.ts CHANGED
@@ -1,4 +1,10 @@
1
- import type { Block, BlockIdentifier, BlockNumber, Uncle } from './block.js'
1
+ import type {
2
+ Block,
3
+ BlockIdentifier,
4
+ BlockNumber,
5
+ BlockTag,
6
+ Uncle,
7
+ } from './block.js'
2
8
  import type { FeeHistory, FeeValues } from './fee.js'
3
9
  import type { Log } from './log.js'
4
10
  import type {
@@ -17,7 +23,15 @@ export type Quantity = `0x${string}`
17
23
  export type Status = '0x0' | '0x1'
18
24
  export type TransactionType = '0x0' | '0x1' | '0x2' | (string & {})
19
25
 
20
- export type RpcBlock = Block<Quantity, RpcTransaction>
26
+ export type RpcBlock<
27
+ TBlockTag extends BlockTag = BlockTag,
28
+ TIncludeTransactions extends boolean = boolean,
29
+ > = Block<
30
+ Quantity,
31
+ TIncludeTransactions,
32
+ TBlockTag,
33
+ RpcTransaction<TBlockTag extends 'pending' ? true : false>
34
+ >
21
35
  export type RpcBlockNumber = BlockNumber<Quantity>
22
36
  export type RpcBlockIdentifier = BlockIdentifier<Quantity>
23
37
  export type RpcUncle = Uncle<Quantity>
@@ -34,9 +48,9 @@ export type RpcTransactionRequest =
34
48
  | TransactionRequestLegacy<Quantity, Index, '0x0'>
35
49
  | TransactionRequestEIP2930<Quantity, Index, '0x1'>
36
50
  | TransactionRequestEIP1559<Quantity, Index, '0x2'>
37
- export type RpcTransaction = UnionOmit<
38
- | TransactionLegacy<Quantity, Index, '0x0'>
39
- | TransactionEIP2930<Quantity, Index, '0x1'>
40
- | TransactionEIP1559<Quantity, Index, '0x2'>,
51
+ export type RpcTransaction<TPending extends boolean = boolean> = UnionOmit<
52
+ | TransactionLegacy<Quantity, Index, TPending, '0x0'>
53
+ | TransactionEIP2930<Quantity, Index, TPending, '0x1'>
54
+ | TransactionEIP1559<Quantity, Index, TPending, '0x2'>,
41
55
  'typeHex'
42
56
  >
@@ -47,11 +47,15 @@ export type TransactionReceipt<
47
47
  type: TType
48
48
  }
49
49
 
50
- export type TransactionBase<TQuantity = bigint, TIndex = number> = {
50
+ export type TransactionBase<
51
+ TQuantity = bigint,
52
+ TIndex = number,
53
+ TPending extends boolean = boolean,
54
+ > = {
51
55
  /** Hash of block containing this transaction or `null` if pending */
52
- blockHash: Hash | null
56
+ blockHash: TPending extends true ? null : Hash
53
57
  /** Number of block containing this transaction or `null` if pending */
54
- blockNumber: TQuantity | null
58
+ blockNumber: TPending extends true ? null : TQuantity
55
59
  /** Transaction sender */
56
60
  from: Address
57
61
  /** Gas provided for transaction execution */
@@ -69,7 +73,7 @@ export type TransactionBase<TQuantity = bigint, TIndex = number> = {
69
73
  /** Transaction recipient or `null` if deploying a contract */
70
74
  to: Address | null
71
75
  /** Index of this transaction in the block or `null` if pending */
72
- transactionIndex: TIndex | null
76
+ transactionIndex: TPending extends true ? null : TIndex
73
77
  /** The type represented as hex. */
74
78
  typeHex: Hex | null
75
79
  /** ECDSA recovery ID */
@@ -80,8 +84,9 @@ export type TransactionBase<TQuantity = bigint, TIndex = number> = {
80
84
  export type TransactionLegacy<
81
85
  TQuantity = bigint,
82
86
  TIndex = number,
87
+ TPending extends boolean = boolean,
83
88
  TType = 'legacy',
84
- > = TransactionBase<TQuantity, TIndex> &
89
+ > = TransactionBase<TQuantity, TIndex, TPending> &
85
90
  FeeValuesLegacy<TQuantity> & {
86
91
  accessList?: never
87
92
  chainId?: TIndex
@@ -90,8 +95,9 @@ export type TransactionLegacy<
90
95
  export type TransactionEIP2930<
91
96
  TQuantity = bigint,
92
97
  TIndex = number,
98
+ TPending extends boolean = boolean,
93
99
  TType = 'eip2930',
94
- > = TransactionBase<TQuantity, TIndex> &
100
+ > = TransactionBase<TQuantity, TIndex, TPending> &
95
101
  FeeValuesLegacy<TQuantity> & {
96
102
  accessList: AccessList
97
103
  chainId: TIndex
@@ -100,17 +106,22 @@ export type TransactionEIP2930<
100
106
  export type TransactionEIP1559<
101
107
  TQuantity = bigint,
102
108
  TIndex = number,
109
+ TPending extends boolean = boolean,
103
110
  TType = 'eip1559',
104
- > = TransactionBase<TQuantity, TIndex> &
111
+ > = TransactionBase<TQuantity, TIndex, TPending> &
105
112
  FeeValuesEIP1559<TQuantity> & {
106
113
  accessList: AccessList
107
114
  chainId: TIndex
108
115
  type: TType
109
116
  }
110
- export type Transaction<TQuantity = bigint, TIndex = number> =
111
- | TransactionLegacy<TQuantity, TIndex>
112
- | TransactionEIP2930<TQuantity, TIndex>
113
- | TransactionEIP1559<TQuantity, TIndex>
117
+ export type Transaction<
118
+ TQuantity = bigint,
119
+ TIndex = number,
120
+ TPending extends boolean = boolean,
121
+ > =
122
+ | TransactionLegacy<TQuantity, TIndex, TPending>
123
+ | TransactionEIP2930<TQuantity, TIndex, TPending>
124
+ | TransactionEIP1559<TQuantity, TIndex, TPending>
114
125
 
115
126
  export type TransactionRequestBase<TQuantity = bigint, TIndex = number> = {
116
127
  /** Contract code or a hashed method call with encoded args */
@@ -1,14 +1,41 @@
1
- import type { Block } from '../../types/block.js'
1
+ import type { Block, BlockTag } from '../../types/block.js'
2
2
  import type { Chain } from '../../types/chain.js'
3
- import type { ExtractFormatterReturnType } from '../../types/formatter.js'
3
+ import type {
4
+ ExtractFormatterExclude,
5
+ ExtractFormatterReturnType,
6
+ } from '../../types/formatter.js'
7
+ import type { Hash } from '../../types/misc.js'
4
8
  import type { RpcBlock } from '../../types/rpc.js'
9
+ import type { Prettify } from '../../types/utils.js'
5
10
 
6
11
  import { defineFormatter } from './formatter.js'
7
- import { formatTransaction } from './transaction.js'
12
+ import { type FormattedTransaction, formatTransaction } from './transaction.js'
13
+
14
+ type BlockPendingDependencies = 'hash' | 'logsBloom' | 'nonce' | 'number'
8
15
 
9
16
  export type FormattedBlock<
10
17
  TChain extends Chain | undefined = Chain | undefined,
11
- > = ExtractFormatterReturnType<TChain, 'block', Block>
18
+ TIncludeTransactions extends boolean = boolean,
19
+ TBlockTag extends BlockTag = BlockTag,
20
+ _FormatterReturnType = ExtractFormatterReturnType<
21
+ TChain,
22
+ 'block',
23
+ Block<bigint, TIncludeTransactions>
24
+ >,
25
+ _ExcludedPendingDependencies extends string = BlockPendingDependencies &
26
+ ExtractFormatterExclude<TChain, 'block'>,
27
+ _Formatted = Omit<_FormatterReturnType, BlockPendingDependencies> & {
28
+ [K in _ExcludedPendingDependencies]: never
29
+ } & Pick<
30
+ Block<bigint, TIncludeTransactions, TBlockTag>,
31
+ BlockPendingDependencies
32
+ >,
33
+ _Transactions = TIncludeTransactions extends true
34
+ ? Prettify<FormattedTransaction<TChain, TBlockTag>>[]
35
+ : Hash[],
36
+ > = Omit<_Formatted, 'transactions'> & {
37
+ transactions: _Transactions
38
+ }
12
39
 
13
40
  export function formatBlock(block: Partial<RpcBlock>) {
14
41
  const transactions = block.transactions?.map((transaction) => {
@@ -16,6 +16,7 @@ export function defineFormatter<TType extends string, TParameters, TReturnType>(
16
16
  format: (_: TOverrideParameters) => TOverrideReturnType
17
17
  }) => {
18
18
  return {
19
+ exclude,
19
20
  format: (args: TParameters & TOverrideParameters) => {
20
21
  const formatted = format(args)
21
22
  if (exclude) {