viem 1.11.1 → 1.12.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 (37) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/_cjs/actions/getContract.js +16 -0
  3. package/_cjs/actions/getContract.js.map +1 -1
  4. package/_cjs/actions/public/getContractEvents.js +25 -0
  5. package/_cjs/actions/public/getContractEvents.js.map +1 -0
  6. package/_cjs/actions/public/watchContractEvent.js +4 -7
  7. package/_cjs/actions/public/watchContractEvent.js.map +1 -1
  8. package/_cjs/clients/decorators/public.js +2 -0
  9. package/_cjs/clients/decorators/public.js.map +1 -1
  10. package/_cjs/errors/node.js +11 -11
  11. package/_cjs/errors/node.js.map +1 -1
  12. package/_cjs/errors/rpc.js +18 -18
  13. package/_cjs/errors/rpc.js.map +1 -1
  14. package/_esm/actions/getContract.js +16 -0
  15. package/_esm/actions/getContract.js.map +1 -1
  16. package/_esm/actions/public/getContractEvents.js +47 -0
  17. package/_esm/actions/public/getContractEvents.js.map +1 -0
  18. package/_esm/actions/public/watchContractEvent.js +4 -7
  19. package/_esm/actions/public/watchContractEvent.js.map +1 -1
  20. package/_esm/clients/decorators/public.js +2 -0
  21. package/_esm/clients/decorators/public.js.map +1 -1
  22. package/_esm/errors/node.js +22 -11
  23. package/_esm/errors/node.js.map +1 -1
  24. package/_esm/errors/rpc.js +36 -18
  25. package/_esm/errors/rpc.js.map +1 -1
  26. package/_types/actions/getContract.d.ts +30 -1
  27. package/_types/actions/getContract.d.ts.map +1 -1
  28. package/_types/actions/public/getContractEvents.d.ts +62 -0
  29. package/_types/actions/public/getContractEvents.d.ts.map +1 -0
  30. package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
  31. package/_types/clients/decorators/public.d.ts +27 -0
  32. package/_types/clients/decorators/public.d.ts.map +1 -1
  33. package/actions/getContract.ts +94 -1
  34. package/actions/public/getContractEvents.ts +139 -0
  35. package/actions/public/watchContractEvent.ts +9 -12
  36. package/clients/decorators/public.ts +48 -0
  37. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import type { Abi, AbiEvent, Address, ExtractAbiEvent } from 'abitype'
1
+ import type { Abi, Address, ExtractAbiEvent } from 'abitype'
2
2
 
3
3
  import type { Client } from '../../clients/createClient.js'
4
4
  import type { Transport } from '../../clients/transports/createTransport.js'
@@ -8,10 +8,6 @@ import type { Filter } from '../../types/filter.js'
8
8
  import type { Log } from '../../types/log.js'
9
9
  import type { GetTransportConfig } from '../../types/transport.js'
10
10
 
11
- import {
12
- type GetAbiItemParameters,
13
- getAbiItem,
14
- } from '../../utils/abi/getAbiItem.js'
15
11
  import { observe } from '../../utils/observe.js'
16
12
  import { poll } from '../../utils/poll.js'
17
13
  import { stringify } from '../../utils/stringify.js'
@@ -33,8 +29,11 @@ import {
33
29
  createContractEventFilter,
34
30
  } from './createContractEventFilter.js'
35
31
  import { getBlockNumber } from './getBlockNumber.js'
32
+ import {
33
+ type GetContractEventsParameters,
34
+ getContractEvents,
35
+ } from './getContractEvents.js'
36
36
  import { getFilterChanges } from './getFilterChanges.js'
37
- import { getLogs } from './getLogs.js'
38
37
  import { uninstallFilter } from './uninstallFilter.js'
39
38
 
40
39
  type PollOptions = {
@@ -213,16 +212,14 @@ export function watchContractEvent<
213
212
  // If the block number doesn't exist, we are yet to reach the first poll interval,
214
213
  // so do not emit any logs.
215
214
  if (previousBlockNumber && previousBlockNumber !== blockNumber) {
216
- logs = await getLogs(client, {
215
+ logs = await getContractEvents(client, {
216
+ abi,
217
217
  address,
218
218
  args,
219
219
  fromBlock: previousBlockNumber + 1n,
220
220
  toBlock: blockNumber,
221
- event: getAbiItem({
222
- abi,
223
- name: eventName,
224
- } as unknown as GetAbiItemParameters) as AbiEvent,
225
- })
221
+ strict,
222
+ } as {} as GetContractEventsParameters)
226
223
  } else {
227
224
  logs = []
228
225
  }
@@ -97,6 +97,11 @@ import {
97
97
  type GetChainIdReturnType,
98
98
  getChainId,
99
99
  } from '../../actions/public/getChainId.js'
100
+ import {
101
+ type GetContractEventsParameters,
102
+ type GetContractEventsReturnType,
103
+ getContractEvents,
104
+ } from '../../actions/public/getContractEvents.js'
100
105
  import {
101
106
  type GetFeeHistoryParameters,
102
107
  type GetFeeHistoryReturnType,
@@ -611,6 +616,48 @@ export type PublicActions<
611
616
  * // 1
612
617
  */
613
618
  getChainId: () => Promise<GetChainIdReturnType>
619
+ /**
620
+ * Returns a list of event logs emitted by a contract.
621
+ *
622
+ * - Docs: https://viem.sh/docs/actions/public/getContractEvents.html
623
+ * - JSON-RPC Methods: [`eth_getLogs`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getlogs)
624
+ *
625
+ * @param client - Client to use
626
+ * @param parameters - {@link GetContractEventsParameters}
627
+ * @returns A list of event logs. {@link GetContractEventsReturnType}
628
+ *
629
+ * @example
630
+ * import { createPublicClient, http } from 'viem'
631
+ * import { mainnet } from 'viem/chains'
632
+ * import { wagmiAbi } from './abi'
633
+ *
634
+ * const client = createPublicClient({
635
+ * chain: mainnet,
636
+ * transport: http(),
637
+ * })
638
+ * const logs = await client.getContractEvents(client, {
639
+ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
640
+ * abi: wagmiAbi,
641
+ * eventName: 'Transfer'
642
+ * })
643
+ */
644
+ getContractEvents: <
645
+ const TAbi extends Abi | readonly unknown[],
646
+ TEventName extends string | undefined = undefined,
647
+ TStrict extends boolean | undefined = undefined,
648
+ TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
649
+ TToBlock extends BlockNumber | BlockTag | undefined = undefined,
650
+ >(
651
+ args: GetContractEventsParameters<
652
+ TAbi,
653
+ TEventName,
654
+ TStrict,
655
+ TFromBlock,
656
+ TToBlock
657
+ >,
658
+ ) => Promise<
659
+ GetContractEventsReturnType<TAbi, TEventName, TStrict, TFromBlock, TToBlock>
660
+ >
614
661
  /**
615
662
  * Gets address for ENS name.
616
663
  *
@@ -1625,6 +1672,7 @@ export function publicActions<
1625
1672
  getBlockTransactionCount: (args) => getBlockTransactionCount(client, args),
1626
1673
  getBytecode: (args) => getBytecode(client, args),
1627
1674
  getChainId: () => getChainId(client),
1675
+ getContractEvents: (args) => getContractEvents(client, args),
1628
1676
  getEnsAddress: (args) => getEnsAddress(client, args),
1629
1677
  getEnsAvatar: (args) => getEnsAvatar(client, args),
1630
1678
  getEnsName: (args) => getEnsName(client, args),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "1.11.1",
4
+ "version": "1.12.0",
5
5
  "type": "module",
6
6
  "main": "./_cjs/index.js",
7
7
  "module": "./_esm/index.js",