viem 0.0.0-main.20230603T024327 → 0.0.0-main.20230604T221342
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.
- package/dist/cjs/actions/ens/getEnsAddress.js +34 -23
- package/dist/cjs/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/cjs/actions/public/call.js +1 -1
- package/dist/cjs/actions/public/call.js.map +1 -1
- package/dist/cjs/actions/public/createContractEventFilter.js +2 -1
- package/dist/cjs/actions/public/createContractEventFilter.js.map +1 -1
- package/dist/cjs/actions/public/createEventFilter.js +2 -1
- package/dist/cjs/actions/public/createEventFilter.js.map +1 -1
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/actions/public/getBlock.js.map +1 -1
- package/dist/cjs/actions/public/getBlockTransactionCount.js +1 -1
- package/dist/cjs/actions/public/getBlockTransactionCount.js.map +1 -1
- package/dist/cjs/actions/public/getChainId.js +3 -1
- package/dist/cjs/actions/public/getChainId.js.map +1 -1
- package/dist/cjs/actions/public/getFilterChanges.js +11 -3
- package/dist/cjs/actions/public/getFilterChanges.js.map +1 -1
- package/dist/cjs/actions/public/getFilterLogs.js +10 -2
- package/dist/cjs/actions/public/getFilterLogs.js.map +1 -1
- package/dist/cjs/actions/public/getGasPrice.js.map +1 -1
- package/dist/cjs/actions/public/getLogs.js +11 -3
- package/dist/cjs/actions/public/getLogs.js.map +1 -1
- package/dist/cjs/actions/public/getTransactionCount.js.map +1 -1
- package/dist/cjs/clients/createClient.js +1 -1
- package/dist/cjs/clients/createClient.js.map +1 -1
- package/dist/cjs/clients/createPublicClient.js.map +1 -1
- package/dist/cjs/clients/createTestClient.js.map +1 -1
- package/dist/cjs/clients/createWalletClient.js.map +1 -1
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/clients/transports/createTransport.js.map +1 -1
- package/dist/cjs/clients/transports/custom.js.map +1 -1
- package/dist/cjs/clients/transports/fallback.js.map +1 -1
- package/dist/cjs/clients/transports/http.js +25 -7
- package/dist/cjs/clients/transports/http.js.map +1 -1
- package/dist/cjs/clients/transports/webSocket.js +22 -14
- package/dist/cjs/clients/transports/webSocket.js.map +1 -1
- package/dist/cjs/errors/abi.js +15 -1
- package/dist/cjs/errors/abi.js.map +1 -1
- package/dist/cjs/errors/request.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/eip1193.js.map +1 -1
- package/dist/cjs/utils/abi/decodeEventLog.js +10 -2
- package/dist/cjs/utils/abi/decodeEventLog.js.map +1 -1
- package/dist/cjs/utils/ens/encodeLabelhash.js +8 -0
- package/dist/cjs/utils/ens/encodeLabelhash.js.map +1 -0
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js +18 -0
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js.map +1 -0
- package/dist/cjs/utils/ens/labelhash.js +2 -1
- package/dist/cjs/utils/ens/labelhash.js.map +1 -1
- package/dist/cjs/utils/ens/namehash.js +5 -1
- package/dist/cjs/utils/ens/namehash.js.map +1 -1
- package/dist/cjs/utils/ens/packetToBytes.js +10 -9
- package/dist/cjs/utils/ens/packetToBytes.js.map +1 -1
- package/dist/cjs/utils/filters/createFilterRequestScope.js.map +1 -1
- package/dist/cjs/utils/formatters/log.js +2 -2
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/rpc.js +12 -17
- package/dist/cjs/utils/rpc.js.map +1 -1
- package/dist/esm/actions/ens/getEnsAddress.js +34 -23
- package/dist/esm/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/esm/actions/public/call.js +1 -1
- package/dist/esm/actions/public/call.js.map +1 -1
- package/dist/esm/actions/public/createContractEventFilter.js +2 -1
- package/dist/esm/actions/public/createContractEventFilter.js.map +1 -1
- package/dist/esm/actions/public/createEventFilter.js +2 -1
- package/dist/esm/actions/public/createEventFilter.js.map +1 -1
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/actions/public/getBlock.js.map +1 -1
- package/dist/esm/actions/public/getBlockTransactionCount.js +1 -1
- package/dist/esm/actions/public/getBlockTransactionCount.js.map +1 -1
- package/dist/esm/actions/public/getChainId.js +3 -1
- package/dist/esm/actions/public/getChainId.js.map +1 -1
- package/dist/esm/actions/public/getFilterChanges.js +11 -3
- package/dist/esm/actions/public/getFilterChanges.js.map +1 -1
- package/dist/esm/actions/public/getFilterLogs.js +10 -2
- package/dist/esm/actions/public/getFilterLogs.js.map +1 -1
- package/dist/esm/actions/public/getGasPrice.js.map +1 -1
- package/dist/esm/actions/public/getLogs.js +11 -3
- package/dist/esm/actions/public/getLogs.js.map +1 -1
- package/dist/esm/actions/public/getTransactionCount.js.map +1 -1
- package/dist/esm/clients/createClient.js +1 -1
- package/dist/esm/clients/createClient.js.map +1 -1
- package/dist/esm/clients/createPublicClient.js.map +1 -1
- package/dist/esm/clients/createTestClient.js.map +1 -1
- package/dist/esm/clients/createWalletClient.js.map +1 -1
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/clients/transports/createTransport.js.map +1 -1
- package/dist/esm/clients/transports/custom.js.map +1 -1
- package/dist/esm/clients/transports/fallback.js.map +1 -1
- package/dist/esm/clients/transports/http.js +25 -7
- package/dist/esm/clients/transports/http.js.map +1 -1
- package/dist/esm/clients/transports/webSocket.js +22 -14
- package/dist/esm/clients/transports/webSocket.js.map +1 -1
- package/dist/esm/errors/abi.js +15 -1
- package/dist/esm/errors/abi.js.map +1 -1
- package/dist/esm/errors/request.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/eip1193.js.map +1 -1
- package/dist/esm/utils/abi/decodeEventLog.js +10 -2
- package/dist/esm/utils/abi/decodeEventLog.js.map +1 -1
- package/dist/esm/utils/ens/encodeLabelhash.js +4 -0
- package/dist/esm/utils/ens/encodeLabelhash.js.map +1 -0
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js +14 -0
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js.map +1 -0
- package/dist/esm/utils/ens/labelhash.js +2 -1
- package/dist/esm/utils/ens/labelhash.js.map +1 -1
- package/dist/esm/utils/ens/namehash.js +6 -2
- package/dist/esm/utils/ens/namehash.js.map +1 -1
- package/dist/esm/utils/ens/packetToBytes.js +10 -9
- package/dist/esm/utils/ens/packetToBytes.js.map +1 -1
- package/dist/esm/utils/filters/createFilterRequestScope.js.map +1 -1
- package/dist/esm/utils/formatters/log.js +2 -2
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/rpc.js +13 -18
- package/dist/esm/utils/rpc.js.map +1 -1
- package/dist/types/actions/ens/getEnsAddress.d.ts.map +1 -1
- package/dist/types/actions/public/createContractEventFilter.d.ts +8 -3
- package/dist/types/actions/public/createContractEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/createEventFilter.d.ts +17 -5
- package/dist/types/actions/public/createEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/getChainId.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterChanges.d.ts +4 -4
- package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterLogs.d.ts +4 -4
- package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/dist/types/actions/public/getLogs.d.ts +10 -4
- package/dist/types/actions/public/getLogs.d.ts.map +1 -1
- package/dist/types/chains.d.ts +4 -4
- package/dist/types/clients/createClient.d.ts +5 -5
- package/dist/types/clients/createClient.d.ts.map +1 -1
- package/dist/types/clients/createPublicClient.d.ts +3 -3
- package/dist/types/clients/createPublicClient.d.ts.map +1 -1
- package/dist/types/clients/createTestClient.d.ts +2 -2
- package/dist/types/clients/createTestClient.d.ts.map +1 -1
- package/dist/types/clients/createWalletClient.d.ts +2 -2
- package/dist/types/clients/createWalletClient.d.ts.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +5 -5
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/clients/transports/createTransport.d.ts +5 -8
- package/dist/types/clients/transports/createTransport.d.ts.map +1 -1
- package/dist/types/clients/transports/custom.d.ts +2 -2
- package/dist/types/clients/transports/custom.d.ts.map +1 -1
- package/dist/types/clients/transports/http.d.ts +11 -0
- package/dist/types/clients/transports/http.d.ts.map +1 -1
- package/dist/types/clients/transports/webSocket.d.ts.map +1 -1
- package/dist/types/errors/abi.d.ts +6 -4
- package/dist/types/errors/abi.d.ts.map +1 -1
- package/dist/types/errors/request.d.ts +16 -8
- package/dist/types/errors/request.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/contract.d.ts +6 -3
- package/dist/types/types/contract.d.ts.map +1 -1
- package/dist/types/types/eip1193.d.ts +1037 -872
- package/dist/types/types/eip1193.d.ts.map +1 -1
- package/dist/types/types/filter.d.ts +12 -3
- package/dist/types/types/filter.d.ts.map +1 -1
- package/dist/types/types/log.d.ts +10 -7
- package/dist/types/types/log.d.ts.map +1 -1
- package/dist/types/types/utils.d.ts +11 -0
- package/dist/types/types/utils.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeEventLog.d.ts.map +1 -1
- package/dist/types/utils/ens/encodeLabelhash.d.ts +3 -0
- package/dist/types/utils/ens/encodeLabelhash.d.ts.map +1 -0
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts +3 -0
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts.map +1 -0
- package/dist/types/utils/ens/labelhash.d.ts.map +1 -1
- package/dist/types/utils/ens/namehash.d.ts.map +1 -1
- package/dist/types/utils/ens/packetToBytes.d.ts.map +1 -1
- package/dist/types/utils/filters/createFilterRequestScope.d.ts +6 -2
- package/dist/types/utils/filters/createFilterRequestScope.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/rpc.d.ts +18 -10
- package/dist/types/utils/rpc.d.ts.map +1 -1
- package/package.json +2 -11
- package/src/actions/ens/getEnsAddress.ts +37 -22
- package/src/actions/public/call.ts +1 -1
- package/src/actions/public/createContractEventFilter.ts +21 -4
- package/src/actions/public/createEventFilter.ts +34 -13
- package/src/actions/public/estimateGas.ts +1 -1
- package/src/actions/public/getBlock.ts +2 -2
- package/src/actions/public/getBlockTransactionCount.ts +1 -1
- package/src/actions/public/getChainId.ts +3 -1
- package/src/actions/public/getFilterChanges.ts +27 -7
- package/src/actions/public/getFilterLogs.ts +29 -8
- package/src/actions/public/getGasPrice.ts +1 -1
- package/src/actions/public/getLogs.ts +34 -10
- package/src/actions/public/getTransactionCount.ts +1 -1
- package/src/clients/createClient.ts +13 -11
- package/src/clients/createPublicClient.ts +3 -4
- package/src/clients/createTestClient.ts +2 -3
- package/src/clients/createWalletClient.ts +2 -3
- package/src/clients/decorators/public.ts +33 -14
- package/src/clients/transports/createTransport.ts +5 -9
- package/src/clients/transports/custom.ts +1 -2
- package/src/clients/transports/fallback.ts +1 -1
- package/src/clients/transports/http.ts +44 -7
- package/src/clients/transports/webSocket.ts +23 -15
- package/src/errors/abi.ts +16 -4
- package/src/errors/request.ts +4 -4
- package/src/errors/version.ts +1 -1
- package/src/index.ts +10 -5
- package/src/types/contract.ts +17 -7
- package/src/types/eip1193.ts +1079 -872
- package/src/types/filter.ts +15 -3
- package/src/types/log.ts +18 -9
- package/src/types/utils.ts +15 -0
- package/src/utils/abi/decodeEventLog.ts +10 -2
- package/src/utils/ens/encodeLabelhash.ts +5 -0
- package/src/utils/ens/encodedLabelToLabelhash.ts +11 -0
- package/src/utils/ens/labelhash.ts +2 -1
- package/src/utils/ens/namehash.ts +6 -2
- package/src/utils/ens/packetToBytes.ts +12 -8
- package/src/utils/filters/createFilterRequestScope.ts +12 -4
- package/src/utils/formatters/log.ts +2 -2
- package/src/utils/index.ts +6 -0
- package/src/utils/rpc.ts +52 -52
- package/dist/cjs/adapters/ethers.js +0 -56
- package/dist/cjs/adapters/ethers.js.map +0 -1
- package/dist/cjs/ethers.js +0 -6
- package/dist/cjs/ethers.js.map +0 -1
- package/dist/esm/adapters/ethers.js +0 -52
- package/dist/esm/adapters/ethers.js.map +0 -1
- package/dist/esm/ethers.js +0 -2
- package/dist/esm/ethers.js.map +0 -1
- package/dist/types/adapters/ethers.d.ts +0 -27
- package/dist/types/adapters/ethers.d.ts.map +0 -1
- package/dist/types/ethers.d.ts +0 -2
- package/dist/types/ethers.d.ts.map +0 -1
- package/ethers/package.json +0 -5
- package/src/adapters/ethers.ts +0 -99
- package/src/ethers.ts +0 -1
@@ -20,47 +20,61 @@ import { createFilterRequestScope } from '../../utils/filters/createFilterReques
|
|
20
20
|
|
21
21
|
export type CreateEventFilterParameters<
|
22
22
|
TAbiEvent extends AbiEvent | undefined = undefined,
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
TStrict extends boolean | undefined = undefined,
|
24
|
+
_Abi extends Abi | readonly unknown[] = [TAbiEvent],
|
25
|
+
_EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
|
26
|
+
_Args extends
|
27
|
+
| MaybeExtractEventArgsFromAbi<_Abi, _EventName>
|
27
28
|
| undefined = undefined,
|
28
29
|
> = {
|
29
30
|
address?: Address | Address[]
|
30
31
|
fromBlock?: BlockNumber | BlockTag
|
31
32
|
toBlock?: BlockNumber | BlockTag
|
32
33
|
} & (MaybeExtractEventArgsFromAbi<
|
33
|
-
|
34
|
-
|
34
|
+
_Abi,
|
35
|
+
_EventName
|
35
36
|
> extends infer TEventFilterArgs
|
36
37
|
?
|
37
38
|
| {
|
38
39
|
args:
|
39
40
|
| TEventFilterArgs
|
40
|
-
| (
|
41
|
+
| (_Args extends TEventFilterArgs ? _Args : never)
|
41
42
|
event: Narrow<TAbiEvent>
|
43
|
+
/**
|
44
|
+
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
45
|
+
* @default false
|
46
|
+
*/
|
47
|
+
strict?: TStrict
|
42
48
|
}
|
43
49
|
| {
|
44
50
|
args?: never
|
45
51
|
event?: Narrow<TAbiEvent>
|
52
|
+
/**
|
53
|
+
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
54
|
+
* @default false
|
55
|
+
*/
|
56
|
+
strict?: TStrict
|
46
57
|
}
|
47
58
|
| {
|
48
59
|
args?: never
|
49
60
|
event?: never
|
61
|
+
strict?: never
|
50
62
|
}
|
51
63
|
: {
|
52
64
|
args?: never
|
53
65
|
event?: never
|
66
|
+
strict?: never
|
54
67
|
})
|
55
68
|
|
56
69
|
export type CreateEventFilterReturnType<
|
57
70
|
TAbiEvent extends AbiEvent | undefined = undefined,
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
71
|
+
TStrict extends boolean | undefined = undefined,
|
72
|
+
_Abi extends Abi | readonly unknown[] = [TAbiEvent],
|
73
|
+
_EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
|
74
|
+
_Args extends
|
75
|
+
| MaybeExtractEventArgsFromAbi<_Abi, _EventName>
|
62
76
|
| undefined = undefined,
|
63
|
-
> = Prettify<Filter<'event',
|
77
|
+
> = Prettify<Filter<'event', _Abi, _EventName, _Args, TStrict>>
|
64
78
|
|
65
79
|
/**
|
66
80
|
* 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).
|
@@ -88,6 +102,7 @@ export type CreateEventFilterReturnType<
|
|
88
102
|
export async function createEventFilter<
|
89
103
|
TChain extends Chain | undefined,
|
90
104
|
TAbiEvent extends AbiEvent | undefined,
|
105
|
+
TStrict extends boolean | undefined,
|
91
106
|
_Abi extends Abi | readonly unknown[] = [TAbiEvent],
|
92
107
|
_EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
|
93
108
|
_Args extends
|
@@ -100,14 +115,18 @@ export async function createEventFilter<
|
|
100
115
|
args,
|
101
116
|
event,
|
102
117
|
fromBlock,
|
118
|
+
strict,
|
103
119
|
toBlock,
|
104
120
|
}: CreateEventFilterParameters<
|
105
121
|
TAbiEvent,
|
122
|
+
TStrict,
|
106
123
|
_Abi,
|
107
124
|
_EventName,
|
108
125
|
_Args
|
109
126
|
> = {} as any,
|
110
|
-
): Promise<
|
127
|
+
): Promise<
|
128
|
+
CreateEventFilterReturnType<TAbiEvent, TStrict, _Abi, _EventName, _Args>
|
129
|
+
> {
|
111
130
|
const getRequest = createFilterRequestScope(client, {
|
112
131
|
method: 'eth_newFilter',
|
113
132
|
})
|
@@ -139,9 +158,11 @@ export async function createEventFilter<
|
|
139
158
|
eventName: event ? (event as AbiEvent).name : undefined,
|
140
159
|
id,
|
141
160
|
request: getRequest(id),
|
161
|
+
strict,
|
142
162
|
type: 'event',
|
143
163
|
} as unknown as CreateEventFilterReturnType<
|
144
164
|
TAbiEvent,
|
165
|
+
TStrict,
|
145
166
|
_Abi,
|
146
167
|
_EventName,
|
147
168
|
_Args
|
@@ -89,12 +89,12 @@ export async function getBlock<
|
|
89
89
|
|
90
90
|
let block: RpcBlock | null = null
|
91
91
|
if (blockHash) {
|
92
|
-
block = await client.request({
|
92
|
+
block = await (client as PublicClient).request({
|
93
93
|
method: 'eth_getBlockByHash',
|
94
94
|
params: [blockHash, includeTransactions],
|
95
95
|
})
|
96
96
|
} else {
|
97
|
-
block = await client.request({
|
97
|
+
block = await (client as PublicClient).request({
|
98
98
|
method: 'eth_getBlockByNumber',
|
99
99
|
params: [blockNumberHex || blockTag, includeTransactions],
|
100
100
|
})
|
@@ -65,7 +65,7 @@ export async function getBlockTransactionCount<
|
|
65
65
|
const blockNumberHex =
|
66
66
|
blockNumber !== undefined ? numberToHex(blockNumber) : undefined
|
67
67
|
|
68
|
-
let count: Quantity
|
68
|
+
let count: Quantity
|
69
69
|
if (blockHash) {
|
70
70
|
count = await client.request({
|
71
71
|
method: 'eth_getBlockTransactionCountByHash',
|
@@ -36,6 +36,8 @@ export async function getChainId<
|
|
36
36
|
| PublicClient<Transport, TChain>
|
37
37
|
| WalletClient<Transport, TChain, TAccount>,
|
38
38
|
): Promise<GetChainIdReturnType> {
|
39
|
-
const chainIdHex = await client.request({
|
39
|
+
const chainIdHex = await (client as PublicClient).request({
|
40
|
+
method: 'eth_chainId',
|
41
|
+
})
|
40
42
|
return hexToNumber(chainIdHex)
|
41
43
|
}
|
@@ -2,6 +2,10 @@ import type { Abi, AbiEvent, ExtractAbiEvent } from 'abitype'
|
|
2
2
|
|
3
3
|
import type { PublicClient } from '../../clients/createPublicClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
5
|
+
import {
|
6
|
+
DecodeLogDataMismatch,
|
7
|
+
DecodeLogTopicsMismatch,
|
8
|
+
} from '../../errors/abi.js'
|
5
9
|
import type { Chain } from '../../types/chain.js'
|
6
10
|
import type { Filter, FilterType } from '../../types/filter.js'
|
7
11
|
import type { Log } from '../../types/log.js'
|
@@ -13,21 +17,23 @@ export type GetFilterChangesParameters<
|
|
13
17
|
TFilterType extends FilterType = FilterType,
|
14
18
|
TAbi extends Abi | readonly unknown[] = Abi,
|
15
19
|
TEventName extends string | undefined = string,
|
20
|
+
TStrict extends boolean | undefined = undefined,
|
16
21
|
> = {
|
17
|
-
filter: Filter<TFilterType, TAbi, TEventName, any>
|
22
|
+
filter: Filter<TFilterType, TAbi, TEventName, any, TStrict>
|
18
23
|
}
|
19
24
|
|
20
25
|
export type GetFilterChangesReturnType<
|
21
26
|
TFilterType extends FilterType = FilterType,
|
22
27
|
TAbi extends Abi | readonly unknown[] = Abi,
|
23
28
|
TEventName extends string | undefined = string,
|
29
|
+
TStrict extends boolean | undefined = undefined,
|
24
30
|
_AbiEvent extends AbiEvent | undefined = TAbi extends Abi
|
25
31
|
? TEventName extends string
|
26
32
|
? ExtractAbiEvent<TAbi, TEventName>
|
27
33
|
: undefined
|
28
34
|
: undefined,
|
29
35
|
> = TFilterType extends 'event'
|
30
|
-
? Log<bigint, number, _AbiEvent, TAbi, TEventName>[]
|
36
|
+
? Log<bigint, number, _AbiEvent, TAbi, TEventName, TStrict>[]
|
31
37
|
: Hash[]
|
32
38
|
|
33
39
|
/**
|
@@ -118,9 +124,12 @@ export async function getFilterChanges<
|
|
118
124
|
TFilterType extends FilterType,
|
119
125
|
TAbi extends Abi | readonly unknown[],
|
120
126
|
TEventName extends string | undefined,
|
127
|
+
TStrict extends boolean | undefined = undefined,
|
121
128
|
>(
|
122
129
|
_client: PublicClient<TTransport, TChain>,
|
123
|
-
{
|
130
|
+
{
|
131
|
+
filter,
|
132
|
+
}: GetFilterChangesParameters<TFilterType, TAbi, TEventName, TStrict>,
|
124
133
|
) {
|
125
134
|
const logs = await filter.request({
|
126
135
|
method: 'eth_getFilterChanges',
|
@@ -139,14 +148,25 @@ export async function getFilterChanges<
|
|
139
148
|
})
|
140
149
|
: { eventName: undefined, args: undefined }
|
141
150
|
return formatLog(log, { args, eventName })
|
142
|
-
} catch {
|
143
|
-
|
144
|
-
|
151
|
+
} catch (err) {
|
152
|
+
let eventName
|
153
|
+
if (
|
154
|
+
err instanceof DecodeLogDataMismatch ||
|
155
|
+
err instanceof DecodeLogTopicsMismatch
|
156
|
+
) {
|
157
|
+
// If strict mode is on, and log data/topics do not match event definition, skip.
|
158
|
+
if ('strict' in filter && filter.strict) return
|
159
|
+
eventName = err.abiItem.name
|
160
|
+
}
|
161
|
+
|
162
|
+
// Set args undefined if there is an error decoding (e.g. indexed/non-indexed params mismatch).
|
163
|
+
return formatLog(log, { args: undefined, eventName })
|
145
164
|
}
|
146
165
|
})
|
147
166
|
.filter(Boolean) as GetFilterChangesReturnType<
|
148
167
|
TFilterType,
|
149
168
|
TAbi,
|
150
|
-
TEventName
|
169
|
+
TEventName,
|
170
|
+
TStrict
|
151
171
|
>
|
152
172
|
}
|
@@ -2,6 +2,10 @@ import type { Abi, AbiEvent, ExtractAbiEvent } from 'abitype'
|
|
2
2
|
|
3
3
|
import type { PublicClient } from '../../clients/createPublicClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
5
|
+
import {
|
6
|
+
DecodeLogDataMismatch,
|
7
|
+
DecodeLogTopicsMismatch,
|
8
|
+
} from '../../errors/abi.js'
|
5
9
|
import type { Chain } from '../../types/chain.js'
|
6
10
|
import type { Filter } from '../../types/filter.js'
|
7
11
|
import type { Log } from '../../types/log.js'
|
@@ -11,18 +15,20 @@ import { formatLog } from '../../utils/formatters/log.js'
|
|
11
15
|
export type GetFilterLogsParameters<
|
12
16
|
TAbi extends Abi | readonly unknown[] = Abi,
|
13
17
|
TEventName extends string | undefined = string,
|
18
|
+
TStrict extends boolean | undefined = undefined,
|
14
19
|
> = {
|
15
|
-
filter: Filter<'event', TAbi, TEventName, any>
|
20
|
+
filter: Filter<'event', TAbi, TEventName, any, TStrict>
|
16
21
|
}
|
17
22
|
export type GetFilterLogsReturnType<
|
18
23
|
TAbi extends Abi | readonly unknown[] = Abi,
|
19
24
|
TEventName extends string | undefined = string,
|
25
|
+
TStrict extends boolean | undefined = undefined,
|
20
26
|
_AbiEvent extends AbiEvent | undefined = TAbi extends Abi
|
21
27
|
? TEventName extends string
|
22
28
|
? ExtractAbiEvent<TAbi, TEventName>
|
23
29
|
: undefined
|
24
30
|
: undefined,
|
25
|
-
> = Log<bigint, number, _AbiEvent, TAbi, TEventName>[]
|
31
|
+
> = Log<bigint, number, _AbiEvent, TAbi, TEventName, TStrict>[]
|
26
32
|
|
27
33
|
/**
|
28
34
|
* Returns a list of event logs since the filter was created.
|
@@ -55,10 +61,11 @@ export async function getFilterLogs<
|
|
55
61
|
TChain extends Chain | undefined,
|
56
62
|
TAbi extends Abi | readonly unknown[],
|
57
63
|
TEventName extends string | undefined,
|
64
|
+
TStrict extends boolean | undefined,
|
58
65
|
>(
|
59
66
|
_client: PublicClient<Transport, TChain>,
|
60
|
-
{ filter }: GetFilterLogsParameters<TAbi, TEventName>,
|
61
|
-
): Promise<GetFilterLogsReturnType<TAbi, TEventName>> {
|
67
|
+
{ filter }: GetFilterLogsParameters<TAbi, TEventName, TStrict>,
|
68
|
+
): Promise<GetFilterLogsReturnType<TAbi, TEventName, TStrict>> {
|
62
69
|
const logs = await filter.request({
|
63
70
|
method: 'eth_getFilterLogs',
|
64
71
|
params: [filter.id],
|
@@ -75,10 +82,24 @@ export async function getFilterLogs<
|
|
75
82
|
})
|
76
83
|
: { eventName: undefined, args: undefined }
|
77
84
|
return formatLog(log, { args, eventName })
|
78
|
-
} catch {
|
79
|
-
|
80
|
-
|
85
|
+
} catch (err) {
|
86
|
+
let eventName
|
87
|
+
if (
|
88
|
+
err instanceof DecodeLogDataMismatch ||
|
89
|
+
err instanceof DecodeLogTopicsMismatch
|
90
|
+
) {
|
91
|
+
// If strict mode is on, and log data/topics do not match event definition, skip.
|
92
|
+
if (filter.strict) return
|
93
|
+
eventName = err.abiItem.name
|
94
|
+
}
|
95
|
+
|
96
|
+
// Set args undefined if there is an error decoding (e.g. indexed/non-indexed params mismatch).
|
97
|
+
return formatLog(log, { args: undefined, eventName })
|
81
98
|
}
|
82
99
|
})
|
83
|
-
.filter(Boolean) as unknown as GetFilterLogsReturnType<
|
100
|
+
.filter(Boolean) as unknown as GetFilterLogsReturnType<
|
101
|
+
TAbi,
|
102
|
+
TEventName,
|
103
|
+
TStrict
|
104
|
+
>
|
84
105
|
}
|
@@ -34,7 +34,7 @@ export async function getGasPrice<
|
|
34
34
|
| PublicClient<Transport, TChain>
|
35
35
|
| WalletClient<Transport, TChain, TAccount>,
|
36
36
|
): Promise<GetGasPriceReturnType> {
|
37
|
-
const gasPrice = await client.request({
|
37
|
+
const gasPrice = await (client as PublicClient).request({
|
38
38
|
method: 'eth_gasPrice',
|
39
39
|
})
|
40
40
|
return BigInt(gasPrice)
|
@@ -2,6 +2,10 @@ import type { AbiEvent, Address, Narrow } from 'abitype'
|
|
2
2
|
|
3
3
|
import type { PublicClient } from '../../clients/createPublicClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
5
|
+
import {
|
6
|
+
DecodeLogDataMismatch,
|
7
|
+
DecodeLogTopicsMismatch,
|
8
|
+
} from '../../errors/abi.js'
|
5
9
|
import type { BlockNumber, BlockTag } from '../../types/block.js'
|
6
10
|
import type { Chain } from '../../types/chain.js'
|
7
11
|
import type {
|
@@ -21,18 +25,25 @@ import { formatLog } from '../../utils/formatters/log.js'
|
|
21
25
|
|
22
26
|
export type GetLogsParameters<
|
23
27
|
TAbiEvent extends AbiEvent | undefined = undefined,
|
24
|
-
|
28
|
+
TStrict extends boolean | undefined = undefined,
|
29
|
+
_EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
|
25
30
|
> = {
|
26
31
|
/** Address or list of addresses from which logs originated */
|
27
32
|
address?: Address | Address[]
|
28
33
|
} & (
|
29
34
|
| {
|
30
35
|
event: Narrow<TAbiEvent>
|
31
|
-
args?: MaybeExtractEventArgsFromAbi<[TAbiEvent],
|
36
|
+
args?: MaybeExtractEventArgsFromAbi<[TAbiEvent], _EventName>
|
37
|
+
/**
|
38
|
+
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
39
|
+
* @default false
|
40
|
+
*/
|
41
|
+
strict?: TStrict
|
32
42
|
}
|
33
43
|
| {
|
34
44
|
event?: never
|
35
45
|
args?: never
|
46
|
+
strict?: never
|
36
47
|
}
|
37
48
|
) &
|
38
49
|
(
|
@@ -53,8 +64,9 @@ export type GetLogsParameters<
|
|
53
64
|
|
54
65
|
export type GetLogsReturnType<
|
55
66
|
TAbiEvent extends AbiEvent | undefined = undefined,
|
56
|
-
|
57
|
-
|
67
|
+
TStrict extends boolean | undefined = undefined,
|
68
|
+
_EventName extends string | undefined = MaybeAbiEventName<TAbiEvent>,
|
69
|
+
> = Log<bigint, number, TAbiEvent, [TAbiEvent], _EventName, TStrict>[]
|
58
70
|
|
59
71
|
/**
|
60
72
|
* Returns a list of event logs matching the provided parameters.
|
@@ -81,6 +93,7 @@ export type GetLogsReturnType<
|
|
81
93
|
export async function getLogs<
|
82
94
|
TChain extends Chain | undefined,
|
83
95
|
TAbiEvent extends AbiEvent | undefined,
|
96
|
+
TStrict extends boolean | undefined,
|
84
97
|
>(
|
85
98
|
client: PublicClient<Transport, TChain>,
|
86
99
|
{
|
@@ -90,8 +103,9 @@ export async function getLogs<
|
|
90
103
|
toBlock,
|
91
104
|
event,
|
92
105
|
args,
|
93
|
-
|
94
|
-
|
106
|
+
strict,
|
107
|
+
}: GetLogsParameters<TAbiEvent, TStrict> = {},
|
108
|
+
): Promise<GetLogsReturnType<TAbiEvent, TStrict>> {
|
95
109
|
let topics: LogTopic[] = []
|
96
110
|
if (event)
|
97
111
|
topics = encodeEventTopics({
|
@@ -132,10 +146,20 @@ export async function getLogs<
|
|
132
146
|
})
|
133
147
|
: { eventName: undefined, args: undefined }
|
134
148
|
return formatLog(log, { args, eventName })
|
135
|
-
} catch {
|
136
|
-
|
137
|
-
|
149
|
+
} catch (err) {
|
150
|
+
let eventName
|
151
|
+
if (
|
152
|
+
err instanceof DecodeLogDataMismatch ||
|
153
|
+
err instanceof DecodeLogTopicsMismatch
|
154
|
+
) {
|
155
|
+
// If strict mode is on, and log data/topics do not match event definition, skip.
|
156
|
+
if (strict) return
|
157
|
+
eventName = err.abiItem.name
|
158
|
+
}
|
159
|
+
|
160
|
+
// Set args undefined if there is an error decoding (e.g. indexed/non-indexed params mismatch).
|
161
|
+
return formatLog(log, { args: undefined, eventName })
|
138
162
|
}
|
139
163
|
})
|
140
|
-
.filter(Boolean) as unknown as GetLogsReturnType<TAbiEvent>
|
164
|
+
.filter(Boolean) as unknown as GetLogsReturnType<TAbiEvent, TStrict>
|
141
165
|
}
|
@@ -58,7 +58,7 @@ export async function getTransactionCount<
|
|
58
58
|
| WalletClient<Transport, TChain, TAccount>,
|
59
59
|
{ address, blockTag = 'latest', blockNumber }: GetTransactionCountParameters,
|
60
60
|
): Promise<GetTransactionCountReturnType> {
|
61
|
-
const count = await client.request({
|
61
|
+
const count = await (client as PublicClient).request({
|
62
62
|
method: 'eth_getTransactionCount',
|
63
63
|
params: [address, blockNumber ? numberToHex(blockNumber) : blockTag],
|
64
64
|
})
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import type { Chain } from '../types/chain.js'
|
2
|
-
import type { Requests } from '../types/eip1193.js'
|
3
|
-
import { uid } from '../utils/uid.js'
|
4
|
-
|
5
2
|
import type {
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
EIP1193RequestFn,
|
4
|
+
EIP1474Methods,
|
5
|
+
RpcSchema,
|
6
|
+
} from '../types/eip1193.js'
|
7
|
+
import { uid } from '../utils/uid.js'
|
8
|
+
import type { Transport } from './transports/createTransport.js'
|
9
9
|
|
10
10
|
export type ClientConfig<
|
11
11
|
TTransport extends Transport = Transport,
|
@@ -30,7 +30,7 @@ export type ClientConfig<
|
|
30
30
|
|
31
31
|
export type Client<
|
32
32
|
TTransport extends Transport = Transport,
|
33
|
-
|
33
|
+
TRpcSchema extends RpcSchema | undefined = undefined,
|
34
34
|
TChain extends Chain | undefined = Chain | undefined,
|
35
35
|
> = {
|
36
36
|
/** Chain for the client. */
|
@@ -42,7 +42,9 @@ export type Client<
|
|
42
42
|
/** Frequency (in ms) for polling enabled actions & events. Defaults to 4_000 milliseconds. */
|
43
43
|
pollingInterval: number
|
44
44
|
/** Request function wrapped with friendly error handling */
|
45
|
-
request:
|
45
|
+
request: TRpcSchema extends undefined
|
46
|
+
? EIP1193RequestFn<EIP1474Methods>
|
47
|
+
: EIP1193RequestFn<TRpcSchema>
|
46
48
|
/** The RPC transport */
|
47
49
|
transport: ReturnType<TTransport>['config'] & ReturnType<TTransport>['value']
|
48
50
|
/** The type of client. */
|
@@ -56,7 +58,7 @@ export type Client<
|
|
56
58
|
*/
|
57
59
|
export function createClient<
|
58
60
|
TTransport extends Transport,
|
59
|
-
|
61
|
+
TRpcSchema extends RpcSchema | undefined = undefined,
|
60
62
|
TChain extends Chain | undefined = undefined,
|
61
63
|
>({
|
62
64
|
chain,
|
@@ -65,14 +67,14 @@ export function createClient<
|
|
65
67
|
pollingInterval = 4_000,
|
66
68
|
transport,
|
67
69
|
type = 'base',
|
68
|
-
}: ClientConfig<TTransport, TChain>): Client<TTransport,
|
70
|
+
}: ClientConfig<TTransport, TChain>): Client<TTransport, TRpcSchema, TChain> {
|
69
71
|
const { config, request, value } = transport({ chain, pollingInterval })
|
70
72
|
return {
|
71
73
|
chain: chain as TChain,
|
72
74
|
key,
|
73
75
|
name,
|
74
76
|
pollingInterval,
|
75
|
-
request,
|
77
|
+
request: request as any,
|
76
78
|
transport: { ...config, ...value },
|
77
79
|
type,
|
78
80
|
uid: uid(),
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import type { Chain } from '../types/chain.js'
|
2
|
-
import type {
|
2
|
+
import type { PublicRpcSchema } from '../types/eip1193.js'
|
3
3
|
import type { Prettify } from '../types/utils.js'
|
4
|
-
|
5
4
|
import { type Client, type ClientConfig, createClient } from './createClient.js'
|
6
5
|
import { type PublicActions, publicActions } from './decorators/public.js'
|
7
6
|
import type { Transport } from './transports/createTransport.js'
|
@@ -9,7 +8,7 @@ import type { Transport } from './transports/createTransport.js'
|
|
9
8
|
export type MulticallBatchOptions = {
|
10
9
|
/** The maximum size (in bytes) for each calldata chunk. @default 1_024 */
|
11
10
|
batchSize?: number
|
12
|
-
/** The maximum number of milliseconds to wait before sending a batch. @default
|
11
|
+
/** The maximum number of milliseconds to wait before sending a batch. @default 0 */
|
13
12
|
wait?: number
|
14
13
|
}
|
15
14
|
|
@@ -32,7 +31,7 @@ export type PublicClient<
|
|
32
31
|
TChain extends Chain | undefined = Chain | undefined,
|
33
32
|
TIncludeActions extends boolean = true,
|
34
33
|
> = Prettify<
|
35
|
-
Client<TTransport,
|
34
|
+
Client<TTransport, PublicRpcSchema, TChain> &
|
36
35
|
Pick<PublicClientConfig, 'batch'> &
|
37
36
|
(TIncludeActions extends true ? PublicActions<TTransport, TChain> : unknown)
|
38
37
|
>
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { Chain } from '../types/chain.js'
|
2
|
-
import type {
|
3
|
-
|
2
|
+
import type { TestRpcSchema } from '../types/eip1193.js'
|
4
3
|
import { type Client, type ClientConfig, createClient } from './createClient.js'
|
5
4
|
import { type TestActions, testActions } from './decorators/test.js'
|
6
5
|
import type { Transport } from './transports/createTransport.js'
|
@@ -24,7 +23,7 @@ export type TestClient<
|
|
24
23
|
TTransport extends Transport = Transport,
|
25
24
|
TChain extends Chain | undefined = Chain | undefined,
|
26
25
|
TIncludeActions extends boolean = true,
|
27
|
-
> = Client<TTransport,
|
26
|
+
> = Client<TTransport, TestRpcSchema<TMode>, TChain> &
|
28
27
|
(TIncludeActions extends true ? TestActions : unknown) & {
|
29
28
|
mode: TMode
|
30
29
|
}
|
@@ -3,9 +3,8 @@ import type { Address } from 'abitype'
|
|
3
3
|
import type { Account, JsonRpcAccount } from '../accounts/types.js'
|
4
4
|
import { parseAccount } from '../accounts/utils/parseAccount.js'
|
5
5
|
import type { Chain } from '../types/chain.js'
|
6
|
-
import type {
|
6
|
+
import type { WalletRpcSchema } from '../types/eip1193.js'
|
7
7
|
import type { Prettify } from '../types/utils.js'
|
8
|
-
|
9
8
|
import { type Client, type ClientConfig, createClient } from './createClient.js'
|
10
9
|
import { type WalletActions, walletActions } from './decorators/wallet.js'
|
11
10
|
import type { Transport } from './transports/createTransport.js'
|
@@ -31,7 +30,7 @@ export type WalletClient<
|
|
31
30
|
TAccount extends Account | undefined = Account | undefined,
|
32
31
|
TIncludeActions extends boolean = true,
|
33
32
|
> = Prettify<
|
34
|
-
Client<TTransport,
|
33
|
+
Client<TTransport, WalletRpcSchema, TChain> &
|
35
34
|
(TIncludeActions extends true
|
36
35
|
? WalletActions<TChain, TAccount>
|
37
36
|
: unknown) & {
|
@@ -277,9 +277,12 @@ export type PublicActions<
|
|
277
277
|
TAbi extends Abi | readonly unknown[],
|
278
278
|
TEventName extends string | undefined,
|
279
279
|
TArgs extends MaybeExtractEventArgsFromAbi<TAbi, TEventName> | undefined,
|
280
|
+
TStrict extends boolean | undefined,
|
280
281
|
>(
|
281
|
-
args: CreateContractEventFilterParameters<TAbi, TEventName, TArgs>,
|
282
|
-
) => Promise<
|
282
|
+
args: CreateContractEventFilterParameters<TAbi, TEventName, TArgs, TStrict>,
|
283
|
+
) => Promise<
|
284
|
+
CreateContractEventFilterReturnType<TAbi, TEventName, TArgs, TStrict>
|
285
|
+
>
|
283
286
|
/**
|
284
287
|
* 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).
|
285
288
|
*
|
@@ -303,12 +306,21 @@ export type PublicActions<
|
|
303
306
|
*/
|
304
307
|
createEventFilter: <
|
305
308
|
TAbiEvent extends AbiEvent | undefined,
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
+
TStrict extends boolean | undefined,
|
310
|
+
_Abi extends Abi | readonly unknown[],
|
311
|
+
_EventName extends string | undefined,
|
312
|
+
_Args extends MaybeExtractEventArgsFromAbi<_Abi, _EventName> | undefined,
|
309
313
|
>(
|
310
|
-
args?: CreateEventFilterParameters<
|
311
|
-
|
314
|
+
args?: CreateEventFilterParameters<
|
315
|
+
TAbiEvent,
|
316
|
+
TStrict,
|
317
|
+
_Abi,
|
318
|
+
_EventName,
|
319
|
+
_Args
|
320
|
+
>,
|
321
|
+
) => Promise<
|
322
|
+
CreateEventFilterReturnType<TAbiEvent, TStrict, _Abi, _EventName, _Args>
|
323
|
+
>
|
312
324
|
/**
|
313
325
|
* Creates a Filter to listen for new pending transaction hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges.html).
|
314
326
|
*
|
@@ -792,9 +804,12 @@ export type PublicActions<
|
|
792
804
|
TFilterType extends FilterType,
|
793
805
|
TAbi extends Abi | readonly unknown[],
|
794
806
|
TEventName extends string | undefined,
|
807
|
+
TStrict extends boolean | undefined,
|
795
808
|
>(
|
796
|
-
args: GetFilterChangesParameters<TFilterType, TAbi, TEventName>,
|
797
|
-
) => Promise<
|
809
|
+
args: GetFilterChangesParameters<TFilterType, TAbi, TEventName, TStrict>,
|
810
|
+
) => Promise<
|
811
|
+
GetFilterChangesReturnType<TFilterType, TAbi, TEventName, TStrict>
|
812
|
+
>
|
798
813
|
/**
|
799
814
|
* Returns a list of event logs since the filter was created.
|
800
815
|
*
|
@@ -824,9 +839,10 @@ export type PublicActions<
|
|
824
839
|
getFilterLogs: <
|
825
840
|
TAbi extends Abi | readonly unknown[],
|
826
841
|
TEventName extends string | undefined,
|
842
|
+
TStrict extends boolean | undefined,
|
827
843
|
>(
|
828
|
-
args: GetFilterLogsParameters<TAbi, TEventName>,
|
829
|
-
) => Promise<GetFilterLogsReturnType<TAbi, TEventName>>
|
844
|
+
args: GetFilterLogsParameters<TAbi, TEventName, TStrict>,
|
845
|
+
) => Promise<GetFilterLogsReturnType<TAbi, TEventName, TStrict>>
|
830
846
|
/**
|
831
847
|
* Returns the current price of gas (in wei).
|
832
848
|
*
|
@@ -866,9 +882,12 @@ export type PublicActions<
|
|
866
882
|
* })
|
867
883
|
* const logs = await client.getLogs()
|
868
884
|
*/
|
869
|
-
getLogs: <
|
870
|
-
|
871
|
-
|
885
|
+
getLogs: <
|
886
|
+
TAbiEvent extends AbiEvent | undefined,
|
887
|
+
TStrict extends boolean | undefined,
|
888
|
+
>(
|
889
|
+
args?: GetLogsParameters<TAbiEvent, TStrict>,
|
890
|
+
) => Promise<GetLogsReturnType<TAbiEvent, TStrict>>
|
872
891
|
/**
|
873
892
|
* Returns the value from a storage slot at a given address.
|
874
893
|
*
|