viem 2.18.4 → 2.18.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/_cjs/chains/definitions/forma.js +33 -0
  3. package/_cjs/chains/definitions/forma.js.map +1 -0
  4. package/_cjs/chains/definitions/sketchpad.js +28 -0
  5. package/_cjs/chains/definitions/sketchpad.js.map +1 -0
  6. package/_cjs/chains/index.js +9 -5
  7. package/_cjs/chains/index.js.map +1 -1
  8. package/_cjs/errors/request.js +21 -3
  9. package/_cjs/errors/request.js.map +1 -1
  10. package/_cjs/errors/version.js +1 -1
  11. package/_cjs/index.js +6 -4
  12. package/_cjs/index.js.map +1 -1
  13. package/_cjs/utils/rpc/socket.js +4 -0
  14. package/_cjs/utils/rpc/socket.js.map +1 -1
  15. package/_cjs/utils/rpc/webSocket.js +3 -4
  16. package/_cjs/utils/rpc/webSocket.js.map +1 -1
  17. package/_esm/chains/definitions/forma.js +30 -0
  18. package/_esm/chains/definitions/forma.js.map +1 -0
  19. package/_esm/chains/definitions/sketchpad.js +25 -0
  20. package/_esm/chains/definitions/sketchpad.js.map +1 -0
  21. package/_esm/chains/index.js +2 -0
  22. package/_esm/chains/index.js.map +1 -1
  23. package/_esm/errors/request.js +19 -2
  24. package/_esm/errors/request.js.map +1 -1
  25. package/_esm/errors/version.js +1 -1
  26. package/_esm/index.js +1 -1
  27. package/_esm/index.js.map +1 -1
  28. package/_esm/utils/rpc/socket.js +6 -1
  29. package/_esm/utils/rpc/socket.js.map +1 -1
  30. package/_esm/utils/rpc/webSocket.js +4 -5
  31. package/_esm/utils/rpc/webSocket.js.map +1 -1
  32. package/_types/chains/definitions/forma.d.ts +35 -0
  33. package/_types/chains/definitions/forma.d.ts.map +1 -0
  34. package/_types/chains/definitions/sketchpad.d.ts +37 -0
  35. package/_types/chains/definitions/sketchpad.d.ts.map +1 -0
  36. package/_types/chains/index.d.ts +2 -0
  37. package/_types/chains/index.d.ts.map +1 -1
  38. package/_types/errors/request.d.ts +14 -4
  39. package/_types/errors/request.d.ts.map +1 -1
  40. package/_types/errors/version.d.ts +1 -1
  41. package/_types/index.d.ts +1 -1
  42. package/_types/index.d.ts.map +1 -1
  43. package/_types/utils/rpc/compat.d.ts.map +1 -1
  44. package/_types/utils/rpc/socket.d.ts.map +1 -1
  45. package/_types/utils/rpc/webSocket.d.ts.map +1 -1
  46. package/chains/definitions/forma.ts +30 -0
  47. package/chains/definitions/sketchpad.ts +25 -0
  48. package/chains/index.ts +2 -0
  49. package/errors/request.ts +26 -3
  50. package/errors/version.ts +1 -1
  51. package/index.ts +2 -0
  52. package/package.json +1 -1
  53. package/utils/rpc/socket.ts +7 -1
  54. package/utils/rpc/webSocket.ts +7 -5
@@ -0,0 +1,30 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const forma = /*#__PURE__*/ defineChain({
4
+ id: 984122,
5
+ name: 'Forma',
6
+ network: 'forma',
7
+ nativeCurrency: {
8
+ symbol: 'TIA',
9
+ name: 'TIA',
10
+ decimals: 18,
11
+ },
12
+ rpcUrls: {
13
+ default: {
14
+ http: ['https://rpc.forma.art'],
15
+ webSocket: ['wss://ws.forma.art'],
16
+ },
17
+ },
18
+ blockExplorers: {
19
+ default: {
20
+ name: 'Forma Explorer',
21
+ url: 'https://explorer.forma.art',
22
+ },
23
+ },
24
+ contracts: {
25
+ multicall3: {
26
+ address: '0xd53C6FFB123F7349A32980F87faeD8FfDc9ef079',
27
+ blockCreated: 252705,
28
+ },
29
+ },
30
+ })
@@ -0,0 +1,25 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const sketchpad = /*#__PURE__*/ defineChain({
4
+ id: 984123,
5
+ name: 'Forma Sketchpad',
6
+ network: 'sketchpad',
7
+ nativeCurrency: {
8
+ symbol: 'TIA',
9
+ name: 'TIA',
10
+ decimals: 18,
11
+ },
12
+ rpcUrls: {
13
+ default: {
14
+ http: ['https://rpc.sketchpad-1.forma.art'],
15
+ webSocket: ['wss://ws.sketchpad-1.forma.art'],
16
+ },
17
+ },
18
+ blockExplorers: {
19
+ default: {
20
+ name: 'Sketchpad Explorer',
21
+ url: 'https://explorer.sketchpad-1.forma.art',
22
+ },
23
+ },
24
+ testnet: true,
25
+ })
package/chains/index.ts CHANGED
@@ -101,6 +101,7 @@ export { flareTestnet } from './definitions/flareTestnet.js'
101
101
  export { flowPreviewnet } from './definitions/flowPreviewnet.js'
102
102
  export { flowMainnet } from './definitions/flowMainnet.js'
103
103
  export { flowTestnet } from './definitions/flowTestnet.js'
104
+ export { forma } from './definitions/forma.js'
104
105
  /** @deprecated Use `anvil` instead. */
105
106
  export { foundry } from './definitions/foundry.js'
106
107
  export { fraxtal } from './definitions/fraxtal.js'
@@ -257,6 +258,7 @@ export { skaleNebulaTestnet } from './definitions/skale/nebulaTestnet.js'
257
258
  export { skaleRazor } from './definitions/skale/razor.js'
258
259
  export { skaleTitan } from './definitions/skale/titan.js'
259
260
  export { skaleTitanTestnet } from './definitions/skale/titanTestnet.js'
261
+ export { sketchpad } from './definitions/sketchpad.js'
260
262
  export { songbird } from './definitions/songbird.js'
261
263
  export { songbirdTestnet } from './definitions/songbirdTestnet.js'
262
264
  export { spicy } from './definitions/spicy.js'
package/errors/request.ts CHANGED
@@ -53,16 +53,22 @@ export class WebSocketRequestError extends BaseError {
53
53
 
54
54
  constructor({
55
55
  body,
56
+ cause,
56
57
  details,
57
58
  url,
58
59
  }: {
59
- body: { [key: string]: unknown }
60
- details: string
60
+ body?: { [key: string]: unknown } | undefined
61
+ cause?: Error | undefined
62
+ details?: string | undefined
61
63
  url: string
62
64
  }) {
63
65
  super('WebSocket request failed.', {
66
+ cause,
64
67
  details,
65
- metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`],
68
+ metaMessages: [
69
+ `URL: ${getUrl(url)}`,
70
+ body && `Request body: ${stringify(body)}`,
71
+ ].filter(Boolean) as string[],
66
72
  })
67
73
  }
68
74
  }
@@ -93,6 +99,23 @@ export class RpcRequestError extends BaseError {
93
99
  }
94
100
  }
95
101
 
102
+ export type SocketClosedErrorType = SocketClosedError & {
103
+ name: 'SocketClosedError'
104
+ }
105
+ export class SocketClosedError extends BaseError {
106
+ override name = 'SocketClosedError'
107
+
108
+ constructor({
109
+ url,
110
+ }: {
111
+ url?: string | undefined
112
+ } = {}) {
113
+ super('The socket has been closed.', {
114
+ metaMessages: [url && `URL: ${getUrl(url)}`].filter(Boolean) as string[],
115
+ })
116
+ }
117
+ }
118
+
96
119
  export type TimeoutErrorType = TimeoutError & {
97
120
  name: 'TimeoutError'
98
121
  }
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.18.4'
1
+ export const version = '2.18.5'
package/index.ts CHANGED
@@ -857,6 +857,8 @@ export {
857
857
  type RpcRequestErrorType,
858
858
  TimeoutError,
859
859
  type TimeoutErrorType,
860
+ SocketClosedError,
861
+ type SocketClosedErrorType,
860
862
  WebSocketRequestError,
861
863
  type WebSocketRequestErrorType,
862
864
  } from './errors/request.js'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.18.4",
4
+ "version": "2.18.5",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -1,4 +1,4 @@
1
- import { TimeoutError } from '../../errors/request.js'
1
+ import { SocketClosedError, TimeoutError } from '../../errors/request.js'
2
2
  import type { ErrorType } from '../../errors/utils.js'
3
3
  import type { RpcRequest, RpcResponse } from '../../types/rpc.js'
4
4
  import {
@@ -134,6 +134,12 @@ export async function getSocketRpcClient<socket extends {}>(
134
134
  async function setup() {
135
135
  const result = await getSocket({
136
136
  onClose() {
137
+ // Notify all requests and subscriptions of the closure error.
138
+ for (const request of requests.values())
139
+ request.onError?.(new SocketClosedError({ url }))
140
+ for (const subscription of subscriptions.values())
141
+ subscription.onError?.(new SocketClosedError({ url }))
142
+
137
143
  // Clear all requests and subscriptions.
138
144
  requests.clear()
139
145
  subscriptions.clear()
@@ -1,6 +1,9 @@
1
1
  import type { MessageEvent } from 'isows'
2
2
 
3
- import { WebSocketRequestError } from '../../errors/request.js'
3
+ import {
4
+ SocketClosedError,
5
+ WebSocketRequestError,
6
+ } from '../../errors/request.js'
4
7
  import {
5
8
  type GetSocketRpcClientParameters,
6
9
  type Socket,
@@ -64,12 +67,11 @@ export async function getWebSocketRpcClient(
64
67
  socket.readyState === socket.CLOSING
65
68
  )
66
69
  throw new WebSocketRequestError({
67
- body: {},
68
70
  url: socket.url,
69
- details: 'Socket is closed.',
71
+ cause: new SocketClosedError({ url: socket.url }),
70
72
  })
71
73
 
72
- socket.send('ping')
74
+ socket.send('net_version')
73
75
  } catch (error) {
74
76
  onError(error as Error)
75
77
  }
@@ -82,7 +84,7 @@ export async function getWebSocketRpcClient(
82
84
  throw new WebSocketRequestError({
83
85
  body,
84
86
  url: socket.url,
85
- details: 'Socket is closed.',
87
+ cause: new SocketClosedError({ url: socket.url }),
86
88
  })
87
89
 
88
90
  return socket.send(JSON.stringify(body))