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.
Files changed (235) hide show
  1. package/dist/cjs/actions/ens/getEnsAddress.js +34 -23
  2. package/dist/cjs/actions/ens/getEnsAddress.js.map +1 -1
  3. package/dist/cjs/actions/public/call.js +1 -1
  4. package/dist/cjs/actions/public/call.js.map +1 -1
  5. package/dist/cjs/actions/public/createContractEventFilter.js +2 -1
  6. package/dist/cjs/actions/public/createContractEventFilter.js.map +1 -1
  7. package/dist/cjs/actions/public/createEventFilter.js +2 -1
  8. package/dist/cjs/actions/public/createEventFilter.js.map +1 -1
  9. package/dist/cjs/actions/public/estimateGas.js.map +1 -1
  10. package/dist/cjs/actions/public/getBlock.js.map +1 -1
  11. package/dist/cjs/actions/public/getBlockTransactionCount.js +1 -1
  12. package/dist/cjs/actions/public/getBlockTransactionCount.js.map +1 -1
  13. package/dist/cjs/actions/public/getChainId.js +3 -1
  14. package/dist/cjs/actions/public/getChainId.js.map +1 -1
  15. package/dist/cjs/actions/public/getFilterChanges.js +11 -3
  16. package/dist/cjs/actions/public/getFilterChanges.js.map +1 -1
  17. package/dist/cjs/actions/public/getFilterLogs.js +10 -2
  18. package/dist/cjs/actions/public/getFilterLogs.js.map +1 -1
  19. package/dist/cjs/actions/public/getGasPrice.js.map +1 -1
  20. package/dist/cjs/actions/public/getLogs.js +11 -3
  21. package/dist/cjs/actions/public/getLogs.js.map +1 -1
  22. package/dist/cjs/actions/public/getTransactionCount.js.map +1 -1
  23. package/dist/cjs/clients/createClient.js +1 -1
  24. package/dist/cjs/clients/createClient.js.map +1 -1
  25. package/dist/cjs/clients/createPublicClient.js.map +1 -1
  26. package/dist/cjs/clients/createTestClient.js.map +1 -1
  27. package/dist/cjs/clients/createWalletClient.js.map +1 -1
  28. package/dist/cjs/clients/decorators/public.js.map +1 -1
  29. package/dist/cjs/clients/transports/createTransport.js.map +1 -1
  30. package/dist/cjs/clients/transports/custom.js.map +1 -1
  31. package/dist/cjs/clients/transports/fallback.js.map +1 -1
  32. package/dist/cjs/clients/transports/http.js +25 -7
  33. package/dist/cjs/clients/transports/http.js.map +1 -1
  34. package/dist/cjs/clients/transports/webSocket.js +22 -14
  35. package/dist/cjs/clients/transports/webSocket.js.map +1 -1
  36. package/dist/cjs/errors/abi.js +15 -1
  37. package/dist/cjs/errors/abi.js.map +1 -1
  38. package/dist/cjs/errors/request.js.map +1 -1
  39. package/dist/cjs/errors/version.js +1 -1
  40. package/dist/cjs/index.js.map +1 -1
  41. package/dist/cjs/types/eip1193.js.map +1 -1
  42. package/dist/cjs/utils/abi/decodeEventLog.js +10 -2
  43. package/dist/cjs/utils/abi/decodeEventLog.js.map +1 -1
  44. package/dist/cjs/utils/ens/encodeLabelhash.js +8 -0
  45. package/dist/cjs/utils/ens/encodeLabelhash.js.map +1 -0
  46. package/dist/cjs/utils/ens/encodedLabelToLabelhash.js +18 -0
  47. package/dist/cjs/utils/ens/encodedLabelToLabelhash.js.map +1 -0
  48. package/dist/cjs/utils/ens/labelhash.js +2 -1
  49. package/dist/cjs/utils/ens/labelhash.js.map +1 -1
  50. package/dist/cjs/utils/ens/namehash.js +5 -1
  51. package/dist/cjs/utils/ens/namehash.js.map +1 -1
  52. package/dist/cjs/utils/ens/packetToBytes.js +10 -9
  53. package/dist/cjs/utils/ens/packetToBytes.js.map +1 -1
  54. package/dist/cjs/utils/filters/createFilterRequestScope.js.map +1 -1
  55. package/dist/cjs/utils/formatters/log.js +2 -2
  56. package/dist/cjs/utils/index.js.map +1 -1
  57. package/dist/cjs/utils/rpc.js +12 -17
  58. package/dist/cjs/utils/rpc.js.map +1 -1
  59. package/dist/esm/actions/ens/getEnsAddress.js +34 -23
  60. package/dist/esm/actions/ens/getEnsAddress.js.map +1 -1
  61. package/dist/esm/actions/public/call.js +1 -1
  62. package/dist/esm/actions/public/call.js.map +1 -1
  63. package/dist/esm/actions/public/createContractEventFilter.js +2 -1
  64. package/dist/esm/actions/public/createContractEventFilter.js.map +1 -1
  65. package/dist/esm/actions/public/createEventFilter.js +2 -1
  66. package/dist/esm/actions/public/createEventFilter.js.map +1 -1
  67. package/dist/esm/actions/public/estimateGas.js.map +1 -1
  68. package/dist/esm/actions/public/getBlock.js.map +1 -1
  69. package/dist/esm/actions/public/getBlockTransactionCount.js +1 -1
  70. package/dist/esm/actions/public/getBlockTransactionCount.js.map +1 -1
  71. package/dist/esm/actions/public/getChainId.js +3 -1
  72. package/dist/esm/actions/public/getChainId.js.map +1 -1
  73. package/dist/esm/actions/public/getFilterChanges.js +11 -3
  74. package/dist/esm/actions/public/getFilterChanges.js.map +1 -1
  75. package/dist/esm/actions/public/getFilterLogs.js +10 -2
  76. package/dist/esm/actions/public/getFilterLogs.js.map +1 -1
  77. package/dist/esm/actions/public/getGasPrice.js.map +1 -1
  78. package/dist/esm/actions/public/getLogs.js +11 -3
  79. package/dist/esm/actions/public/getLogs.js.map +1 -1
  80. package/dist/esm/actions/public/getTransactionCount.js.map +1 -1
  81. package/dist/esm/clients/createClient.js +1 -1
  82. package/dist/esm/clients/createClient.js.map +1 -1
  83. package/dist/esm/clients/createPublicClient.js.map +1 -1
  84. package/dist/esm/clients/createTestClient.js.map +1 -1
  85. package/dist/esm/clients/createWalletClient.js.map +1 -1
  86. package/dist/esm/clients/decorators/public.js.map +1 -1
  87. package/dist/esm/clients/transports/createTransport.js.map +1 -1
  88. package/dist/esm/clients/transports/custom.js.map +1 -1
  89. package/dist/esm/clients/transports/fallback.js.map +1 -1
  90. package/dist/esm/clients/transports/http.js +25 -7
  91. package/dist/esm/clients/transports/http.js.map +1 -1
  92. package/dist/esm/clients/transports/webSocket.js +22 -14
  93. package/dist/esm/clients/transports/webSocket.js.map +1 -1
  94. package/dist/esm/errors/abi.js +15 -1
  95. package/dist/esm/errors/abi.js.map +1 -1
  96. package/dist/esm/errors/request.js.map +1 -1
  97. package/dist/esm/errors/version.js +1 -1
  98. package/dist/esm/index.js.map +1 -1
  99. package/dist/esm/types/eip1193.js.map +1 -1
  100. package/dist/esm/utils/abi/decodeEventLog.js +10 -2
  101. package/dist/esm/utils/abi/decodeEventLog.js.map +1 -1
  102. package/dist/esm/utils/ens/encodeLabelhash.js +4 -0
  103. package/dist/esm/utils/ens/encodeLabelhash.js.map +1 -0
  104. package/dist/esm/utils/ens/encodedLabelToLabelhash.js +14 -0
  105. package/dist/esm/utils/ens/encodedLabelToLabelhash.js.map +1 -0
  106. package/dist/esm/utils/ens/labelhash.js +2 -1
  107. package/dist/esm/utils/ens/labelhash.js.map +1 -1
  108. package/dist/esm/utils/ens/namehash.js +6 -2
  109. package/dist/esm/utils/ens/namehash.js.map +1 -1
  110. package/dist/esm/utils/ens/packetToBytes.js +10 -9
  111. package/dist/esm/utils/ens/packetToBytes.js.map +1 -1
  112. package/dist/esm/utils/filters/createFilterRequestScope.js.map +1 -1
  113. package/dist/esm/utils/formatters/log.js +2 -2
  114. package/dist/esm/utils/index.js.map +1 -1
  115. package/dist/esm/utils/rpc.js +13 -18
  116. package/dist/esm/utils/rpc.js.map +1 -1
  117. package/dist/types/actions/ens/getEnsAddress.d.ts.map +1 -1
  118. package/dist/types/actions/public/createContractEventFilter.d.ts +8 -3
  119. package/dist/types/actions/public/createContractEventFilter.d.ts.map +1 -1
  120. package/dist/types/actions/public/createEventFilter.d.ts +17 -5
  121. package/dist/types/actions/public/createEventFilter.d.ts.map +1 -1
  122. package/dist/types/actions/public/getChainId.d.ts.map +1 -1
  123. package/dist/types/actions/public/getFilterChanges.d.ts +4 -4
  124. package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
  125. package/dist/types/actions/public/getFilterLogs.d.ts +4 -4
  126. package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
  127. package/dist/types/actions/public/getLogs.d.ts +10 -4
  128. package/dist/types/actions/public/getLogs.d.ts.map +1 -1
  129. package/dist/types/chains.d.ts +4 -4
  130. package/dist/types/clients/createClient.d.ts +5 -5
  131. package/dist/types/clients/createClient.d.ts.map +1 -1
  132. package/dist/types/clients/createPublicClient.d.ts +3 -3
  133. package/dist/types/clients/createPublicClient.d.ts.map +1 -1
  134. package/dist/types/clients/createTestClient.d.ts +2 -2
  135. package/dist/types/clients/createTestClient.d.ts.map +1 -1
  136. package/dist/types/clients/createWalletClient.d.ts +2 -2
  137. package/dist/types/clients/createWalletClient.d.ts.map +1 -1
  138. package/dist/types/clients/decorators/public.d.ts +5 -5
  139. package/dist/types/clients/decorators/public.d.ts.map +1 -1
  140. package/dist/types/clients/transports/createTransport.d.ts +5 -8
  141. package/dist/types/clients/transports/createTransport.d.ts.map +1 -1
  142. package/dist/types/clients/transports/custom.d.ts +2 -2
  143. package/dist/types/clients/transports/custom.d.ts.map +1 -1
  144. package/dist/types/clients/transports/http.d.ts +11 -0
  145. package/dist/types/clients/transports/http.d.ts.map +1 -1
  146. package/dist/types/clients/transports/webSocket.d.ts.map +1 -1
  147. package/dist/types/errors/abi.d.ts +6 -4
  148. package/dist/types/errors/abi.d.ts.map +1 -1
  149. package/dist/types/errors/request.d.ts +16 -8
  150. package/dist/types/errors/request.d.ts.map +1 -1
  151. package/dist/types/errors/version.d.ts +1 -1
  152. package/dist/types/index.d.ts +1 -1
  153. package/dist/types/index.d.ts.map +1 -1
  154. package/dist/types/types/contract.d.ts +6 -3
  155. package/dist/types/types/contract.d.ts.map +1 -1
  156. package/dist/types/types/eip1193.d.ts +1037 -872
  157. package/dist/types/types/eip1193.d.ts.map +1 -1
  158. package/dist/types/types/filter.d.ts +12 -3
  159. package/dist/types/types/filter.d.ts.map +1 -1
  160. package/dist/types/types/log.d.ts +10 -7
  161. package/dist/types/types/log.d.ts.map +1 -1
  162. package/dist/types/types/utils.d.ts +11 -0
  163. package/dist/types/types/utils.d.ts.map +1 -1
  164. package/dist/types/utils/abi/decodeEventLog.d.ts.map +1 -1
  165. package/dist/types/utils/ens/encodeLabelhash.d.ts +3 -0
  166. package/dist/types/utils/ens/encodeLabelhash.d.ts.map +1 -0
  167. package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts +3 -0
  168. package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts.map +1 -0
  169. package/dist/types/utils/ens/labelhash.d.ts.map +1 -1
  170. package/dist/types/utils/ens/namehash.d.ts.map +1 -1
  171. package/dist/types/utils/ens/packetToBytes.d.ts.map +1 -1
  172. package/dist/types/utils/filters/createFilterRequestScope.d.ts +6 -2
  173. package/dist/types/utils/filters/createFilterRequestScope.d.ts.map +1 -1
  174. package/dist/types/utils/index.d.ts +1 -1
  175. package/dist/types/utils/index.d.ts.map +1 -1
  176. package/dist/types/utils/rpc.d.ts +18 -10
  177. package/dist/types/utils/rpc.d.ts.map +1 -1
  178. package/package.json +2 -11
  179. package/src/actions/ens/getEnsAddress.ts +37 -22
  180. package/src/actions/public/call.ts +1 -1
  181. package/src/actions/public/createContractEventFilter.ts +21 -4
  182. package/src/actions/public/createEventFilter.ts +34 -13
  183. package/src/actions/public/estimateGas.ts +1 -1
  184. package/src/actions/public/getBlock.ts +2 -2
  185. package/src/actions/public/getBlockTransactionCount.ts +1 -1
  186. package/src/actions/public/getChainId.ts +3 -1
  187. package/src/actions/public/getFilterChanges.ts +27 -7
  188. package/src/actions/public/getFilterLogs.ts +29 -8
  189. package/src/actions/public/getGasPrice.ts +1 -1
  190. package/src/actions/public/getLogs.ts +34 -10
  191. package/src/actions/public/getTransactionCount.ts +1 -1
  192. package/src/clients/createClient.ts +13 -11
  193. package/src/clients/createPublicClient.ts +3 -4
  194. package/src/clients/createTestClient.ts +2 -3
  195. package/src/clients/createWalletClient.ts +2 -3
  196. package/src/clients/decorators/public.ts +33 -14
  197. package/src/clients/transports/createTransport.ts +5 -9
  198. package/src/clients/transports/custom.ts +1 -2
  199. package/src/clients/transports/fallback.ts +1 -1
  200. package/src/clients/transports/http.ts +44 -7
  201. package/src/clients/transports/webSocket.ts +23 -15
  202. package/src/errors/abi.ts +16 -4
  203. package/src/errors/request.ts +4 -4
  204. package/src/errors/version.ts +1 -1
  205. package/src/index.ts +10 -5
  206. package/src/types/contract.ts +17 -7
  207. package/src/types/eip1193.ts +1079 -872
  208. package/src/types/filter.ts +15 -3
  209. package/src/types/log.ts +18 -9
  210. package/src/types/utils.ts +15 -0
  211. package/src/utils/abi/decodeEventLog.ts +10 -2
  212. package/src/utils/ens/encodeLabelhash.ts +5 -0
  213. package/src/utils/ens/encodedLabelToLabelhash.ts +11 -0
  214. package/src/utils/ens/labelhash.ts +2 -1
  215. package/src/utils/ens/namehash.ts +6 -2
  216. package/src/utils/ens/packetToBytes.ts +12 -8
  217. package/src/utils/filters/createFilterRequestScope.ts +12 -4
  218. package/src/utils/formatters/log.ts +2 -2
  219. package/src/utils/index.ts +6 -0
  220. package/src/utils/rpc.ts +52 -52
  221. package/dist/cjs/adapters/ethers.js +0 -56
  222. package/dist/cjs/adapters/ethers.js.map +0 -1
  223. package/dist/cjs/ethers.js +0 -6
  224. package/dist/cjs/ethers.js.map +0 -1
  225. package/dist/esm/adapters/ethers.js +0 -52
  226. package/dist/esm/adapters/ethers.js.map +0 -1
  227. package/dist/esm/ethers.js +0 -2
  228. package/dist/esm/ethers.js.map +0 -1
  229. package/dist/types/adapters/ethers.d.ts +0 -27
  230. package/dist/types/adapters/ethers.d.ts.map +0 -1
  231. package/dist/types/ethers.d.ts +0 -2
  232. package/dist/types/ethers.d.ts.map +0 -1
  233. package/ethers/package.json +0 -5
  234. package/src/adapters/ethers.ts +0 -99
  235. package/src/ethers.ts +0 -1
@@ -1,22 +1,18 @@
1
1
  import type { Chain } from '../../types/chain.js'
2
- import type { Requests } from '../../types/eip1193.js'
2
+ import type { EIP1193RequestFn } from '../../types/eip1193.js'
3
3
  import { buildRequest } from '../../utils/buildRequest.js'
4
4
  import type { ClientConfig } from '../createClient.js'
5
5
 
6
- export type BaseRpcRequests = {
7
- request(...args: any): Promise<any>
8
- }
9
-
10
6
  export type TransportConfig<
11
7
  TType extends string = string,
12
- TRequests extends BaseRpcRequests['request'] = Requests['request'],
8
+ TEIP1193RequestFn extends EIP1193RequestFn = EIP1193RequestFn,
13
9
  > = {
14
10
  /** The name of the transport. */
15
11
  name: string
16
12
  /** The key of the transport. */
17
13
  key: string
18
14
  /** The JSON-RPC request function that matches the EIP-1193 request spec. */
19
- request: TRequests
15
+ request: TEIP1193RequestFn
20
16
  /** The base delay (in ms) between retries. */
21
17
  retryDelay?: number
22
18
  /** The max number of times to retry. */
@@ -30,7 +26,7 @@ export type TransportConfig<
30
26
  export type Transport<
31
27
  TType extends string = string,
32
28
  TRpcAttributes = Record<string, any>,
33
- TRequests extends BaseRpcRequests['request'] = Requests['request'],
29
+ TEIP1193RequestFn extends EIP1193RequestFn = EIP1193RequestFn,
34
30
  > = <TChain extends Chain | undefined = Chain>({
35
31
  chain,
36
32
  }: {
@@ -40,7 +36,7 @@ export type Transport<
40
36
  timeout?: TransportConfig['timeout']
41
37
  }) => {
42
38
  config: TransportConfig<TType>
43
- request: TRequests
39
+ request: TEIP1193RequestFn
44
40
  value?: TRpcAttributes
45
41
  }
46
42
 
@@ -1,11 +1,10 @@
1
1
  import {
2
- type BaseRpcRequests,
3
2
  type Transport,
4
3
  type TransportConfig,
5
4
  createTransport,
6
5
  } from './createTransport.js'
7
6
 
8
- type EthereumProvider = { request: BaseRpcRequests['request'] }
7
+ type EthereumProvider = { request(...args: any): Promise<any> }
9
8
 
10
9
  export type CustomTransportConfig = {
11
10
  /** The key of the transport. */
@@ -102,7 +102,7 @@ export function fallback(
102
102
  key,
103
103
  name,
104
104
  async request({ method, params }) {
105
- const fetch = async (i: number = 0): Promise<any> => {
105
+ const fetch = async (i = 0): Promise<any> => {
106
106
  const transport = transports[i]({ chain, retryCount: 0, timeout })
107
107
  try {
108
108
  const response = await transport.request({
@@ -1,5 +1,7 @@
1
+ import { RpcRequestError } from '../../errors/request.js'
1
2
  import { UrlRequiredError } from '../../errors/transport.js'
2
- import { type HttpOptions, rpc } from '../../utils/rpc.js'
3
+ import { createBatchScheduler } from '../../utils/promise/createBatchScheduler.js'
4
+ import { type HttpOptions, type RpcRequest, rpc } from '../../utils/rpc.js'
3
5
 
4
6
  import {
5
7
  type Transport,
@@ -7,7 +9,19 @@ import {
7
9
  createTransport,
8
10
  } from './createTransport.js'
9
11
 
12
+ export type BatchOptions = {
13
+ /** The maximum number of JSON-RPC requests to send in a batch. @default 1_000 */
14
+ batchSize?: number
15
+ /** The maximum number of milliseconds to wait before sending a batch. @default 0 */
16
+ wait?: number
17
+ }
18
+
10
19
  export type HttpTransportConfig = {
20
+ /**
21
+ * Whether to enable Batch JSON-RPC.
22
+ * @link https://www.jsonrpc.org/specification#batch
23
+ */
24
+ batch?: boolean | BatchOptions
11
25
  /**
12
26
  * Request configuration to pass to `fetch`.
13
27
  * @link https://developer.mozilla.org/en-US/docs/Web/API/fetch
@@ -41,12 +55,15 @@ export function http(
41
55
  config: HttpTransportConfig = {},
42
56
  ): HttpTransport {
43
57
  const {
58
+ batch,
44
59
  fetchOptions,
45
60
  key = 'http',
46
61
  name = 'HTTP JSON-RPC',
47
62
  retryDelay,
48
63
  } = config
49
64
  return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {
65
+ const { batchSize = 1000, wait = 0 } =
66
+ typeof batch === 'object' ? batch : {}
50
67
  const retryCount = config.retryCount ?? retryCount_
51
68
  const timeout = timeout_ ?? config.timeout ?? 10_000
52
69
  const url_ = url || chain?.rpcUrls.default.http[0]
@@ -56,14 +73,34 @@ export function http(
56
73
  key,
57
74
  name,
58
75
  async request({ method, params }) {
59
- const { result } = await rpc.http(url_, {
60
- body: {
61
- method,
62
- params,
76
+ const body = { method, params }
77
+
78
+ const { schedule } = createBatchScheduler({
79
+ id: `${url}`,
80
+ wait,
81
+ shouldSplitBatch(requests) {
82
+ return requests.length > batchSize
63
83
  },
64
- fetchOptions,
65
- timeout,
84
+ fn: (body: RpcRequest[]) =>
85
+ rpc.http(url_, {
86
+ body,
87
+ fetchOptions,
88
+ timeout,
89
+ }),
66
90
  })
91
+
92
+ const fn = async (body: RpcRequest) =>
93
+ batch
94
+ ? schedule(body)
95
+ : [await rpc.http(url_, { body, fetchOptions, timeout })]
96
+
97
+ const [{ error, result }] = await fn(body)
98
+ if (error)
99
+ throw new RpcRequestError({
100
+ body,
101
+ error,
102
+ url: url_,
103
+ })
67
104
  return result
68
105
  },
69
106
  retryCount,
@@ -1,9 +1,9 @@
1
1
  import type { WebSocket } from 'isomorphic-ws'
2
2
 
3
+ import { RpcRequestError } from '../../errors/request.js'
3
4
  import { UrlRequiredError } from '../../errors/transport.js'
4
5
  import type { Hash } from '../../types/misc.js'
5
6
  import { type RpcResponse, getSocket, rpc } from '../../utils/rpc.js'
6
-
7
7
  import {
8
8
  type Transport,
9
9
  type TransportConfig,
@@ -72,11 +72,18 @@ export function webSocket(
72
72
  key,
73
73
  name,
74
74
  async request({ method, params }) {
75
+ const body = { method, params }
75
76
  const socket = await getSocket(url_)
76
- const { result } = await rpc.webSocketAsync(socket, {
77
- body: { method, params },
77
+ const { error, result } = await rpc.webSocketAsync(socket, {
78
+ body,
78
79
  timeout,
79
80
  })
81
+ if (error)
82
+ throw new RpcRequestError({
83
+ body,
84
+ error,
85
+ url: url_,
86
+ })
80
87
  return result
81
88
  },
82
89
  retryCount,
@@ -97,31 +104,32 @@ export function webSocket(
97
104
  method: 'eth_subscribe',
98
105
  params,
99
106
  },
100
- onData: (data) => {
101
- if (typeof data.id === 'number') {
102
- resolve(data)
107
+ onResponse(response) {
108
+ if (response.error) {
109
+ reject(response.error)
110
+ onError?.(response.error)
103
111
  return
104
112
  }
105
- if (data.method !== 'eth_subscription') return
106
- onData(data.params)
107
- },
108
- onError: (error) => {
109
- reject(error)
110
- onError?.(error)
113
+
114
+ if (typeof response.id === 'number') {
115
+ resolve(response)
116
+ return
117
+ }
118
+ if (response.method !== 'eth_subscription') return
119
+ onData(response.params)
111
120
  },
112
121
  }),
113
122
  )
114
123
  return {
115
124
  subscriptionId,
116
125
  async unsubscribe() {
117
- return new Promise<any>((resolve, reject) =>
126
+ return new Promise<any>((resolve) =>
118
127
  rpc.webSocket(socket, {
119
128
  body: {
120
129
  method: 'eth_unsubscribe',
121
130
  params: [subscriptionId],
122
131
  },
123
- onData: resolve,
124
- onError: reject,
132
+ onResponse: resolve,
125
133
  }),
126
134
  )
127
135
  },
package/src/errors/abi.ts CHANGED
@@ -1,6 +1,5 @@
1
- import type { AbiParameter } from 'abitype'
1
+ import type { AbiEvent, AbiParameter } from 'abitype'
2
2
 
3
- import type { AbiItem } from '../types/contract.js'
4
3
  import type { Hex } from '../types/misc.js'
5
4
  import { formatAbiItem, formatAbiParams } from '../utils/abi/formatAbiItem.js'
6
5
  import { size } from '../utils/data/size.js'
@@ -278,15 +277,22 @@ export class BytesSizeMismatchError extends BaseError {
278
277
  export class DecodeLogDataMismatch extends BaseError {
279
278
  override name = 'DecodeLogDataMismatch'
280
279
 
280
+ abiItem: AbiEvent
281
281
  data: Hex
282
282
  params: readonly AbiParameter[]
283
283
  size: number
284
284
 
285
285
  constructor({
286
+ abiItem,
286
287
  data,
287
288
  params,
288
289
  size,
289
- }: { data: Hex; params: readonly AbiParameter[]; size: number }) {
290
+ }: {
291
+ abiItem: AbiEvent
292
+ data: Hex
293
+ params: readonly AbiParameter[]
294
+ size: number
295
+ }) {
290
296
  super(
291
297
  [
292
298
  `Data size of ${size} bytes is too small for non-indexed event parameters.`,
@@ -299,6 +305,7 @@ export class DecodeLogDataMismatch extends BaseError {
299
305
  },
300
306
  )
301
307
 
308
+ this.abiItem = abiItem
302
309
  this.data = data
303
310
  this.params = params
304
311
  this.size = size
@@ -307,11 +314,14 @@ export class DecodeLogDataMismatch extends BaseError {
307
314
 
308
315
  export class DecodeLogTopicsMismatch extends BaseError {
309
316
  override name = 'DecodeLogTopicsMismatch'
317
+
318
+ abiItem: AbiEvent
319
+
310
320
  constructor({
311
321
  abiItem,
312
322
  param,
313
323
  }: {
314
- abiItem: AbiItem
324
+ abiItem: AbiEvent
315
325
  param: AbiParameter & { indexed: boolean }
316
326
  }) {
317
327
  super(
@@ -321,6 +331,8 @@ export class DecodeLogTopicsMismatch extends BaseError {
321
331
  } on event "${formatAbiItem(abiItem, { includeName: true })}".`,
322
332
  ].join('\n'),
323
333
  )
334
+
335
+ this.abiItem = abiItem
324
336
  }
325
337
  }
326
338
 
@@ -6,7 +6,7 @@ import { getUrl } from './utils.js'
6
6
  export class HttpRequestError extends BaseError {
7
7
  override name = 'HttpRequestError'
8
8
 
9
- body?: { [key: string]: unknown }
9
+ body?: { [x: string]: unknown } | { [y: string]: unknown }[]
10
10
  headers?: Headers
11
11
  status?: number
12
12
  url: string
@@ -18,7 +18,7 @@ export class HttpRequestError extends BaseError {
18
18
  status,
19
19
  url,
20
20
  }: {
21
- body?: { [key: string]: unknown }
21
+ body?: { [x: string]: unknown } | { [y: string]: unknown }[]
22
22
  details?: string
23
23
  headers?: Headers
24
24
  status?: number
@@ -68,7 +68,7 @@ export class RpcRequestError extends BaseError {
68
68
  error,
69
69
  url,
70
70
  }: {
71
- body: { [key: string]: unknown }
71
+ body: { [x: string]: unknown } | { [y: string]: unknown }[]
72
72
  error: { code: number; message: string }
73
73
  url: string
74
74
  }) {
@@ -88,7 +88,7 @@ export class TimeoutError extends BaseError {
88
88
  body,
89
89
  url,
90
90
  }: {
91
- body: { [key: string]: unknown }
91
+ body: { [x: string]: unknown } | { [y: string]: unknown }[]
92
92
  url: string
93
93
  }) {
94
94
  super('The request took too long to respond.', {
@@ -1 +1 @@
1
- export const version = '0.0.0-main.20230603T024327'
1
+ export const version = '0.0.0-main.20230604T221342'
package/src/index.ts CHANGED
@@ -447,19 +447,24 @@ export {
447
447
  } from './types/misc.js'
448
448
  export type { Chain } from './types/chain.js'
449
449
  export type {
450
+ AddEthereumChainParameter,
451
+ EIP1193Events,
452
+ EIP1193Parameters,
450
453
  EIP1193Provider,
454
+ EIP1193RequestFn,
455
+ EIP1474Methods,
451
456
  ProviderRpcError as EIP1193ProviderRpcError,
452
457
  ProviderConnectInfo,
453
458
  ProviderMessage,
454
- AddEthereumChainParameter,
459
+ PublicRpcSchema,
455
460
  NetworkSync,
456
- PublicRequests,
457
- Requests,
458
- SignableRequests,
461
+ RpcSchema,
462
+ RpcSchemaOverride,
463
+ TestRpcSchema,
459
464
  WatchAssetParams,
460
465
  WalletPermissionCaveat,
461
466
  WalletPermission,
462
- WalletRequests,
467
+ WalletRpcSchema,
463
468
  } from './types/eip1193.js'
464
469
  export {
465
470
  type FeeHistory,
@@ -20,7 +20,7 @@ import type {
20
20
 
21
21
  import type { Hex, LogTopic } from './misc.js'
22
22
  import type { TransactionRequest } from './transaction.js'
23
- import type { Filter, NoUndefined } from './utils.js'
23
+ import type { Filter, MaybeRequired, NoUndefined, Prettify } from './utils.js'
24
24
 
25
25
  export type AbiItem = Abi[number]
26
26
 
@@ -238,7 +238,7 @@ export type GetEventArgsFromTopics<
238
238
  : AbiEvent & { type: 'event' },
239
239
  TArgs = AbiEventParametersToPrimitiveTypes<
240
240
  TAbiEvent['inputs'],
241
- { EnableUnion: false; IndexedOnly: false }
241
+ { EnableUnion: false; IndexedOnly: false; Required: true }
242
242
  >,
243
243
  > = TTopics extends readonly []
244
244
  ? TData extends undefined
@@ -252,10 +252,12 @@ export type GetEventArgsFromTopics<
252
252
  type EventParameterOptions = {
253
253
  EnableUnion?: boolean
254
254
  IndexedOnly?: boolean
255
+ Required?: boolean
255
256
  }
256
257
  type DefaultEventParameterOptions = {
257
258
  EnableUnion: true
258
259
  IndexedOnly: true
260
+ Required: false
259
261
  }
260
262
 
261
263
  type HashedEventTypes = 'bytes' | 'string' | 'tuple' | `${string}[${string}]`
@@ -328,10 +330,13 @@ export type AbiEventParametersToPrimitiveTypes<
328
330
  },
329
331
  ]
330
332
  // Distribute over tuple to represent optional parameters
331
- | (Filtered extends readonly [
332
- ...infer Head extends readonly AbiParameter[],
333
- infer _,
334
- ]
333
+ | (Options['Required'] extends true
334
+ ? never
335
+ : // Distribute over tuple to represent optional parameters
336
+ Filtered extends readonly [
337
+ ...infer Head extends readonly AbiParameter[],
338
+ infer _,
339
+ ]
335
340
  ? AbiEventParametersToPrimitiveTypes<
336
341
  readonly [...{ [K in keyof Head]: Omit<Head[K], 'name'> }],
337
342
  Options
@@ -346,6 +351,11 @@ export type AbiEventParametersToPrimitiveTypes<
346
351
  ? Name
347
352
  : never]?: AbiEventParameterToPrimitiveType<Parameter, Options>
348
353
  } extends infer Mapped
349
- ? Mapped
354
+ ? Prettify<
355
+ MaybeRequired<
356
+ Mapped,
357
+ Options['Required'] extends boolean ? Options['Required'] : false
358
+ >
359
+ >
350
360
  : never
351
361
  : never