viem 2.9.22 → 2.9.24

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 (227) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/_cjs/accounts/privateKeyToAccount.js +4 -0
  3. package/_cjs/accounts/privateKeyToAccount.js.map +1 -1
  4. package/_cjs/accounts/toAccount.js +1 -0
  5. package/_cjs/accounts/toAccount.js.map +1 -1
  6. package/_cjs/actions/public/watchBlockNumber.js +20 -2
  7. package/_cjs/actions/public/watchBlockNumber.js.map +1 -1
  8. package/_cjs/actions/public/watchBlocks.js +20 -2
  9. package/_cjs/actions/public/watchBlocks.js.map +1 -1
  10. package/_cjs/actions/public/watchContractEvent.js +22 -4
  11. package/_cjs/actions/public/watchContractEvent.js.map +1 -1
  12. package/_cjs/actions/public/watchEvent.js +22 -4
  13. package/_cjs/actions/public/watchEvent.js.map +1 -1
  14. package/_cjs/chains/definitions/cyberTestnet.js +29 -0
  15. package/_cjs/chains/definitions/cyberTestnet.js.map +1 -0
  16. package/_cjs/chains/definitions/dreyerxMainnet.js +25 -0
  17. package/_cjs/chains/definitions/dreyerxMainnet.js.map +1 -0
  18. package/_cjs/chains/index.js +9 -5
  19. package/_cjs/chains/index.js.map +1 -1
  20. package/_cjs/clients/transports/fallback.js +2 -2
  21. package/_cjs/clients/transports/fallback.js.map +1 -1
  22. package/_cjs/errors/version.js +1 -1
  23. package/_cjs/experimental/eip3074/actions/signAuthMessage.js +18 -0
  24. package/_cjs/experimental/eip3074/actions/signAuthMessage.js.map +1 -0
  25. package/_cjs/experimental/eip3074/decorators/eip3074.js +13 -0
  26. package/_cjs/experimental/eip3074/decorators/eip3074.js.map +1 -0
  27. package/_cjs/experimental/eip3074/utils/recoverAuthMessageAddress.js +12 -0
  28. package/_cjs/experimental/eip3074/utils/recoverAuthMessageAddress.js.map +1 -0
  29. package/_cjs/experimental/eip3074/utils/signAuthMessage.js +17 -0
  30. package/_cjs/experimental/eip3074/utils/signAuthMessage.js.map +1 -0
  31. package/_cjs/experimental/eip3074/utils/toAuthMessage.js +17 -0
  32. package/_cjs/experimental/eip3074/utils/toAuthMessage.js.map +1 -0
  33. package/_cjs/experimental/eip3074/utils/verifyAuthMessage.js +11 -0
  34. package/_cjs/experimental/eip3074/utils/verifyAuthMessage.js.map +1 -0
  35. package/_cjs/experimental/{actions → eip5792/actions}/getCallsStatus.js +2 -2
  36. package/_cjs/experimental/eip5792/actions/getCallsStatus.js.map +1 -0
  37. package/_cjs/experimental/{actions → eip5792/actions}/getCapabilities.js +2 -2
  38. package/_cjs/experimental/eip5792/actions/getCapabilities.js.map +1 -0
  39. package/_cjs/experimental/{actions → eip5792/actions}/sendCalls.js +6 -6
  40. package/_cjs/experimental/eip5792/actions/sendCalls.js.map +1 -0
  41. package/_cjs/experimental/eip5792/actions/showCallsStatus.js.map +1 -0
  42. package/_cjs/experimental/{actions → eip5792/actions}/writeContracts.js +1 -1
  43. package/_cjs/experimental/eip5792/actions/writeContracts.js.map +1 -0
  44. package/_cjs/experimental/eip5792/decorators/eip5792.js.map +1 -0
  45. package/_cjs/experimental/index.js +15 -7
  46. package/_cjs/experimental/index.js.map +1 -1
  47. package/_cjs/utils/signature/hexToSignature.js.map +1 -1
  48. package/_esm/accounts/privateKeyToAccount.js +4 -0
  49. package/_esm/accounts/privateKeyToAccount.js.map +1 -1
  50. package/_esm/accounts/toAccount.js +1 -0
  51. package/_esm/accounts/toAccount.js.map +1 -1
  52. package/_esm/actions/public/verifyHash.js +1 -1
  53. package/_esm/actions/public/waitForTransactionReceipt.js +1 -1
  54. package/_esm/actions/public/watchBlockNumber.js +20 -2
  55. package/_esm/actions/public/watchBlockNumber.js.map +1 -1
  56. package/_esm/actions/public/watchBlocks.js +20 -2
  57. package/_esm/actions/public/watchBlocks.js.map +1 -1
  58. package/_esm/actions/public/watchContractEvent.js +22 -4
  59. package/_esm/actions/public/watchContractEvent.js.map +1 -1
  60. package/_esm/actions/public/watchEvent.js +22 -4
  61. package/_esm/actions/public/watchEvent.js.map +1 -1
  62. package/_esm/chains/definitions/cyberTestnet.js +26 -0
  63. package/_esm/chains/definitions/cyberTestnet.js.map +1 -0
  64. package/_esm/chains/definitions/dreyerxMainnet.js +22 -0
  65. package/_esm/chains/definitions/dreyerxMainnet.js.map +1 -0
  66. package/_esm/chains/index.js +2 -0
  67. package/_esm/chains/index.js.map +1 -1
  68. package/_esm/clients/transports/fallback.js +2 -2
  69. package/_esm/clients/transports/fallback.js.map +1 -1
  70. package/_esm/errors/version.js +1 -1
  71. package/_esm/experimental/eip3074/actions/signAuthMessage.js +69 -0
  72. package/_esm/experimental/eip3074/actions/signAuthMessage.js.map +1 -0
  73. package/_esm/experimental/eip3074/decorators/eip3074.js +26 -0
  74. package/_esm/experimental/eip3074/decorators/eip3074.js.map +1 -0
  75. package/_esm/experimental/eip3074/utils/recoverAuthMessageAddress.js +8 -0
  76. package/_esm/experimental/eip3074/utils/recoverAuthMessageAddress.js.map +1 -0
  77. package/_esm/experimental/eip3074/utils/signAuthMessage.js +16 -0
  78. package/_esm/experimental/eip3074/utils/signAuthMessage.js.map +1 -0
  79. package/_esm/experimental/eip3074/utils/toAuthMessage.js +17 -0
  80. package/_esm/experimental/eip3074/utils/toAuthMessage.js.map +1 -0
  81. package/_esm/experimental/eip3074/utils/verifyAuthMessage.js +13 -0
  82. package/_esm/experimental/eip3074/utils/verifyAuthMessage.js.map +1 -0
  83. package/_esm/experimental/{actions → eip5792/actions}/getCallsStatus.js +3 -3
  84. package/_esm/experimental/eip5792/actions/getCallsStatus.js.map +1 -0
  85. package/_esm/experimental/{actions → eip5792/actions}/getCapabilities.js +3 -3
  86. package/_esm/experimental/eip5792/actions/getCapabilities.js.map +1 -0
  87. package/_esm/experimental/{actions → eip5792/actions}/sendCalls.js +7 -7
  88. package/_esm/experimental/eip5792/actions/sendCalls.js.map +1 -0
  89. package/_esm/experimental/{actions → eip5792/actions}/showCallsStatus.js +1 -1
  90. package/_esm/experimental/eip5792/actions/showCallsStatus.js.map +1 -0
  91. package/_esm/experimental/{actions → eip5792/actions}/writeContracts.js +2 -2
  92. package/_esm/experimental/eip5792/actions/writeContracts.js.map +1 -0
  93. package/_esm/experimental/eip5792/decorators/eip5792.js.map +1 -0
  94. package/_esm/experimental/index.js +10 -6
  95. package/_esm/experimental/index.js.map +1 -1
  96. package/_esm/utils/signature/hexToSignature.js.map +1 -1
  97. package/_types/accounts/privateKeyToAccount.d.ts.map +1 -1
  98. package/_types/accounts/toAccount.d.ts.map +1 -1
  99. package/_types/accounts/types.d.ts +5 -3
  100. package/_types/accounts/types.d.ts.map +1 -1
  101. package/_types/actions/public/verifyHash.d.ts +1 -1
  102. package/_types/actions/public/waitForTransactionReceipt.d.ts +1 -1
  103. package/_types/actions/public/watchBlockNumber.d.ts +2 -2
  104. package/_types/actions/public/watchBlockNumber.d.ts.map +1 -1
  105. package/_types/actions/public/watchBlocks.d.ts +2 -2
  106. package/_types/actions/public/watchBlocks.d.ts.map +1 -1
  107. package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
  108. package/_types/actions/public/watchEvent.d.ts.map +1 -1
  109. package/_types/celo/chainConfig.d.ts +114 -114
  110. package/_types/celo/formatters.d.ts +57 -57
  111. package/_types/chains/definitions/ancient8.d.ts +45 -45
  112. package/_types/chains/definitions/ancient8Sepolia.d.ts +45 -45
  113. package/_types/chains/definitions/base.d.ts +45 -45
  114. package/_types/chains/definitions/baseGoerli.d.ts +45 -45
  115. package/_types/chains/definitions/baseSepolia.d.ts +45 -45
  116. package/_types/chains/definitions/celo.d.ts +114 -114
  117. package/_types/chains/definitions/celoAlfajores.d.ts +114 -114
  118. package/_types/chains/definitions/cyberTestnet.d.ts +34 -0
  119. package/_types/chains/definitions/cyberTestnet.d.ts.map +1 -0
  120. package/_types/chains/definitions/dreyerxMainnet.d.ts +35 -0
  121. package/_types/chains/definitions/dreyerxMainnet.d.ts.map +1 -0
  122. package/_types/chains/definitions/fraxtal.d.ts +45 -45
  123. package/_types/chains/definitions/fraxtalTestnet.d.ts +45 -45
  124. package/_types/chains/definitions/liskSepolia.d.ts +45 -45
  125. package/_types/chains/definitions/optimism.d.ts +45 -45
  126. package/_types/chains/definitions/optimismGoerli.d.ts +45 -45
  127. package/_types/chains/definitions/optimismSepolia.d.ts +45 -45
  128. package/_types/chains/definitions/pgn.d.ts +45 -45
  129. package/_types/chains/definitions/pgnTestnet.d.ts +45 -45
  130. package/_types/chains/definitions/rss3.d.ts +45 -45
  131. package/_types/chains/definitions/rss3Sepolia.d.ts +45 -45
  132. package/_types/chains/definitions/zora.d.ts +45 -45
  133. package/_types/chains/definitions/zoraSepolia.d.ts +45 -45
  134. package/_types/chains/definitions/zoraTestnet.d.ts +45 -45
  135. package/_types/chains/index.d.ts +2 -0
  136. package/_types/chains/index.d.ts.map +1 -1
  137. package/_types/clients/transports/fallback.d.ts +5 -3
  138. package/_types/clients/transports/fallback.d.ts.map +1 -1
  139. package/_types/errors/version.d.ts +1 -1
  140. package/_types/experimental/eip3074/actions/signAuthMessage.d.ts +72 -0
  141. package/_types/experimental/eip3074/actions/signAuthMessage.d.ts.map +1 -0
  142. package/_types/experimental/eip3074/decorators/eip3074.d.ts +27 -0
  143. package/_types/experimental/eip3074/decorators/eip3074.d.ts.map +1 -0
  144. package/_types/experimental/eip3074/utils/recoverAuthMessageAddress.d.ts +12 -0
  145. package/_types/experimental/eip3074/utils/recoverAuthMessageAddress.d.ts.map +1 -0
  146. package/_types/experimental/eip3074/utils/signAuthMessage.d.ts +16 -0
  147. package/_types/experimental/eip3074/utils/signAuthMessage.d.ts.map +1 -0
  148. package/_types/experimental/eip3074/utils/toAuthMessage.d.ts +20 -0
  149. package/_types/experimental/eip3074/utils/toAuthMessage.d.ts.map +1 -0
  150. package/_types/experimental/eip3074/utils/verifyAuthMessage.d.ts +19 -0
  151. package/_types/experimental/eip3074/utils/verifyAuthMessage.d.ts.map +1 -0
  152. package/_types/experimental/{actions → eip5792/actions}/getCallsStatus.d.ts +9 -9
  153. package/_types/experimental/eip5792/actions/getCallsStatus.d.ts.map +1 -0
  154. package/_types/experimental/{actions → eip5792/actions}/getCapabilities.d.ts +9 -9
  155. package/_types/experimental/eip5792/actions/getCapabilities.d.ts.map +1 -0
  156. package/_types/experimental/{actions → eip5792/actions}/sendCalls.d.ts +10 -10
  157. package/_types/experimental/eip5792/actions/sendCalls.d.ts.map +1 -0
  158. package/_types/experimental/{actions → eip5792/actions}/showCallsStatus.d.ts +7 -7
  159. package/_types/experimental/eip5792/actions/showCallsStatus.d.ts.map +1 -0
  160. package/_types/experimental/{actions → eip5792/actions}/writeContracts.d.ts +9 -9
  161. package/_types/experimental/eip5792/actions/writeContracts.d.ts.map +1 -0
  162. package/_types/experimental/{decorators → eip5792/decorators}/eip5792.d.ts +9 -9
  163. package/_types/experimental/eip5792/decorators/eip5792.d.ts.map +1 -0
  164. package/_types/experimental/index.d.ts +10 -6
  165. package/_types/experimental/index.d.ts.map +1 -1
  166. package/_types/op-stack/chainConfig.d.ts +45 -45
  167. package/_types/op-stack/formatters.d.ts +45 -45
  168. package/_types/types/transport.d.ts +6 -1
  169. package/_types/types/transport.d.ts.map +1 -1
  170. package/_types/types/utils.d.ts +11 -0
  171. package/_types/types/utils.d.ts.map +1 -1
  172. package/_types/utils/formatters/transaction.d.ts +1 -1
  173. package/_types/utils/formatters/transactionRequest.d.ts +1 -1
  174. package/_types/utils/signature/hexToSignature.d.ts +7 -2
  175. package/_types/utils/signature/hexToSignature.d.ts.map +1 -1
  176. package/accounts/privateKeyToAccount.ts +5 -1
  177. package/accounts/toAccount.ts +1 -0
  178. package/accounts/types.ts +12 -5
  179. package/actions/public/verifyHash.ts +1 -1
  180. package/actions/public/waitForTransactionReceipt.ts +1 -1
  181. package/actions/public/watchBlockNumber.ts +36 -17
  182. package/actions/public/watchBlocks.ts +25 -5
  183. package/actions/public/watchContractEvent.ts +66 -48
  184. package/actions/public/watchEvent.ts +24 -5
  185. package/chains/definitions/cyberTestnet.ts +26 -0
  186. package/chains/definitions/dreyerxMainnet.ts +22 -0
  187. package/chains/index.ts +2 -0
  188. package/clients/transports/fallback.ts +16 -13
  189. package/errors/version.ts +1 -1
  190. package/experimental/eip3074/actions/signAuthMessage.ts +103 -0
  191. package/experimental/eip3074/decorators/eip3074.ts +51 -0
  192. package/experimental/eip3074/utils/recoverAuthMessageAddress.ts +29 -0
  193. package/experimental/eip3074/utils/signAuthMessage.ts +40 -0
  194. package/experimental/eip3074/utils/toAuthMessage.ts +50 -0
  195. package/experimental/eip3074/utils/verifyAuthMessage.ts +46 -0
  196. package/experimental/{actions → eip5792/actions}/getCallsStatus.ts +11 -11
  197. package/experimental/{actions → eip5792/actions}/getCapabilities.ts +11 -11
  198. package/experimental/{actions → eip5792/actions}/sendCalls.ts +17 -17
  199. package/experimental/{actions → eip5792/actions}/showCallsStatus.ts +7 -7
  200. package/experimental/{actions → eip5792/actions}/writeContracts.ts +9 -9
  201. package/experimental/{decorators → eip5792/decorators}/eip5792.ts +9 -9
  202. package/experimental/index.ts +29 -7
  203. package/package.json +1 -1
  204. package/types/transport.ts +16 -1
  205. package/types/utils.ts +16 -0
  206. package/utils/signature/hexToSignature.ts +2 -2
  207. package/_cjs/experimental/actions/getCallsStatus.js.map +0 -1
  208. package/_cjs/experimental/actions/getCapabilities.js.map +0 -1
  209. package/_cjs/experimental/actions/sendCalls.js.map +0 -1
  210. package/_cjs/experimental/actions/showCallsStatus.js.map +0 -1
  211. package/_cjs/experimental/actions/writeContracts.js.map +0 -1
  212. package/_cjs/experimental/decorators/eip5792.js.map +0 -1
  213. package/_esm/experimental/actions/getCallsStatus.js.map +0 -1
  214. package/_esm/experimental/actions/getCapabilities.js.map +0 -1
  215. package/_esm/experimental/actions/sendCalls.js.map +0 -1
  216. package/_esm/experimental/actions/showCallsStatus.js.map +0 -1
  217. package/_esm/experimental/actions/writeContracts.js.map +0 -1
  218. package/_esm/experimental/decorators/eip5792.js.map +0 -1
  219. package/_types/experimental/actions/getCallsStatus.d.ts.map +0 -1
  220. package/_types/experimental/actions/getCapabilities.d.ts.map +0 -1
  221. package/_types/experimental/actions/sendCalls.d.ts.map +0 -1
  222. package/_types/experimental/actions/showCallsStatus.d.ts.map +0 -1
  223. package/_types/experimental/actions/writeContracts.d.ts.map +0 -1
  224. package/_types/experimental/decorators/eip5792.d.ts.map +0 -1
  225. /package/_cjs/experimental/{actions → eip5792/actions}/showCallsStatus.js +0 -0
  226. /package/_cjs/experimental/{decorators → eip5792/decorators}/eip5792.js +0 -0
  227. /package/_esm/experimental/{decorators → eip5792/decorators}/eip5792.js +0 -0
@@ -3,7 +3,7 @@ import type { Transport } from '../../clients/transports/createTransport.js'
3
3
  import type { ErrorType } from '../../errors/utils.js'
4
4
  import type { BlockTag } from '../../types/block.js'
5
5
  import type { Chain } from '../../types/chain.js'
6
- import type { GetTransportConfig } from '../../types/transport.js'
6
+ import type { HasTransportType } from '../../types/transport.js'
7
7
  import { formatBlock } from '../../utils/formatters/block.js'
8
8
  import { getAction } from '../../utils/getAction.js'
9
9
  import { observe } from '../../utils/observe.js'
@@ -40,7 +40,7 @@ export type WatchBlocksParameters<
40
40
  /** The callback to call when an error occurred when trying to get for a new block. */
41
41
  onError?: ((error: Error) => void) | undefined
42
42
  } & (
43
- | (GetTransportConfig<TTransport>['type'] extends 'webSocket'
43
+ | (HasTransportType<TTransport, 'webSocket'> extends true
44
44
  ? {
45
45
  blockTag?: undefined
46
46
  emitMissed?: undefined
@@ -116,8 +116,16 @@ export function watchBlocks<
116
116
  pollingInterval = client.pollingInterval,
117
117
  }: WatchBlocksParameters<TTransport, TChain, TIncludeTransactions, TBlockTag>,
118
118
  ): WatchBlocksReturnType {
119
- const enablePolling =
120
- typeof poll_ !== 'undefined' ? poll_ : client.transport.type !== 'webSocket'
119
+ const enablePolling = (() => {
120
+ if (typeof poll_ !== 'undefined') return poll_
121
+ if (client.transport.type === 'webSocket') return false
122
+ if (
123
+ client.transport.type === 'fallback' &&
124
+ client.transport.transports[0].config.type === 'webSocket'
125
+ )
126
+ return false
127
+ return true
128
+ })()
121
129
  const includeTransactions = includeTransactions_ ?? false
122
130
 
123
131
  let prevBlock:
@@ -199,7 +207,19 @@ export function watchBlocks<
199
207
  let unsubscribe = () => (active = false)
200
208
  ;(async () => {
201
209
  try {
202
- const { unsubscribe: unsubscribe_ } = await client.transport.subscribe({
210
+ const transport = (() => {
211
+ if (client.transport.type === 'fallback') {
212
+ const transport = client.transport.transports.find(
213
+ (transport: ReturnType<Transport>) =>
214
+ transport.config.type === 'webSocket',
215
+ )
216
+ if (!transport) return client.transport
217
+ return transport.value
218
+ }
219
+ return client.transport
220
+ })()
221
+
222
+ const { unsubscribe: unsubscribe_ } = await transport.subscribe({
203
223
  params: ['newHeads'],
204
224
  onData(data: any) {
205
225
  if (!active) return
@@ -154,10 +154,17 @@ export function watchContractEvent<
154
154
  strict: strict_,
155
155
  } = parameters
156
156
 
157
- const enablePolling =
158
- typeof poll_ !== 'undefined'
159
- ? poll_
160
- : client.transport.type !== 'webSocket' || typeof fromBlock === 'number'
157
+ const enablePolling = (() => {
158
+ if (typeof poll_ !== 'undefined') return poll_
159
+ if (typeof fromBlock === 'bigint') return true
160
+ if (client.transport.type === 'webSocket') return false
161
+ if (
162
+ client.transport.type === 'fallback' &&
163
+ client.transport.transports[0].config.type === 'webSocket'
164
+ )
165
+ return false
166
+ return true
167
+ })()
161
168
 
162
169
  const pollContractEvent = () => {
163
170
  const strict = strict_ ?? false
@@ -289,6 +296,18 @@ export function watchContractEvent<
289
296
  return observe(observerId, { onLogs, onError }, (emit) => {
290
297
  ;(async () => {
291
298
  try {
299
+ const transport = (() => {
300
+ if (client.transport.type === 'fallback') {
301
+ const transport = client.transport.transports.find(
302
+ (transport: ReturnType<Transport>) =>
303
+ transport.config.type === 'webSocket',
304
+ )
305
+ if (!transport) return client.transport
306
+ return transport.value
307
+ }
308
+ return client.transport
309
+ })()
310
+
292
311
  const topics: LogTopic[] = eventName
293
312
  ? encodeEventTopics({
294
313
  abi: abi,
@@ -297,51 +316,50 @@ export function watchContractEvent<
297
316
  } as EncodeEventTopicsParameters)
298
317
  : []
299
318
 
300
- const { unsubscribe: unsubscribe_ } =
301
- await client.transport.subscribe({
302
- params: ['logs', { address, topics }],
303
- onData(data: any) {
304
- if (!active) return
305
- const log = data.result
306
- try {
307
- const { eventName, args } = decodeEventLog({
308
- abi: abi,
309
- data: log.data,
310
- topics: log.topics as any,
311
- strict: strict_,
312
- })
313
- const formatted = formatLog(log, {
314
- args,
315
- eventName: eventName as string,
316
- })
317
- emit.onLogs([formatted] as any)
318
- } catch (err) {
319
- let eventName: string | undefined
320
- let isUnnamed: boolean | undefined
321
- if (
322
- err instanceof DecodeLogDataMismatch ||
323
- err instanceof DecodeLogTopicsMismatch
324
- ) {
325
- // If strict mode is on, and log data/topics do not match event definition, skip.
326
- if (strict_) return
327
- eventName = err.abiItem.name
328
- isUnnamed = err.abiItem.inputs?.some(
329
- (x) => !('name' in x && x.name),
330
- )
331
- }
332
-
333
- // Set args to empty if there is an error decoding (e.g. indexed/non-indexed params mismatch).
334
- const formatted = formatLog(log, {
335
- args: isUnnamed ? [] : {},
336
- eventName,
337
- })
338
- emit.onLogs([formatted] as any)
319
+ const { unsubscribe: unsubscribe_ } = await transport.subscribe({
320
+ params: ['logs', { address, topics }],
321
+ onData(data: any) {
322
+ if (!active) return
323
+ const log = data.result
324
+ try {
325
+ const { eventName, args } = decodeEventLog({
326
+ abi: abi,
327
+ data: log.data,
328
+ topics: log.topics as any,
329
+ strict: strict_,
330
+ })
331
+ const formatted = formatLog(log, {
332
+ args,
333
+ eventName: eventName as string,
334
+ })
335
+ emit.onLogs([formatted] as any)
336
+ } catch (err) {
337
+ let eventName: string | undefined
338
+ let isUnnamed: boolean | undefined
339
+ if (
340
+ err instanceof DecodeLogDataMismatch ||
341
+ err instanceof DecodeLogTopicsMismatch
342
+ ) {
343
+ // If strict mode is on, and log data/topics do not match event definition, skip.
344
+ if (strict_) return
345
+ eventName = err.abiItem.name
346
+ isUnnamed = err.abiItem.inputs?.some(
347
+ (x) => !('name' in x && x.name),
348
+ )
339
349
  }
340
- },
341
- onError(error: Error) {
342
- emit.onError?.(error)
343
- },
344
- })
350
+
351
+ // Set args to empty if there is an error decoding (e.g. indexed/non-indexed params mismatch).
352
+ const formatted = formatLog(log, {
353
+ args: isUnnamed ? [] : {},
354
+ eventName,
355
+ })
356
+ emit.onLogs([formatted] as any)
357
+ }
358
+ },
359
+ onError(error: Error) {
360
+ emit.onError?.(error)
361
+ },
362
+ })
345
363
  unsubscribe = unsubscribe_
346
364
  if (!active) unsubscribe()
347
365
  } catch (err) {
@@ -172,10 +172,17 @@ export function watchEvent<
172
172
  strict: strict_,
173
173
  }: WatchEventParameters<TAbiEvent, TAbiEvents, TStrict, TTransport>,
174
174
  ): WatchEventReturnType {
175
- const enablePolling =
176
- typeof poll_ !== 'undefined'
177
- ? poll_
178
- : client.transport.type !== 'webSocket' || typeof fromBlock === 'bigint'
175
+ const enablePolling = (() => {
176
+ if (typeof poll_ !== 'undefined') return poll_
177
+ if (typeof fromBlock === 'bigint') return true
178
+ if (client.transport.type === 'webSocket') return false
179
+ if (
180
+ client.transport.type === 'fallback' &&
181
+ client.transport.transports[0].config.type === 'webSocket'
182
+ )
183
+ return false
184
+ return true
185
+ })()
179
186
  const strict = strict_ ?? false
180
187
 
181
188
  const pollEvent = () => {
@@ -296,6 +303,18 @@ export function watchEvent<
296
303
  let unsubscribe = () => (active = false)
297
304
  ;(async () => {
298
305
  try {
306
+ const transport = (() => {
307
+ if (client.transport.type === 'fallback') {
308
+ const transport = client.transport.transports.find(
309
+ (transport: ReturnType<Transport>) =>
310
+ transport.config.type === 'webSocket',
311
+ )
312
+ if (!transport) return client.transport
313
+ return transport.value
314
+ }
315
+ return client.transport
316
+ })()
317
+
299
318
  const events_ = events ?? (event ? [event] : undefined)
300
319
  let topics: LogTopic[] = []
301
320
  if (events_) {
@@ -311,7 +330,7 @@ export function watchEvent<
311
330
  if (event) topics = topics[0] as LogTopic[]
312
331
  }
313
332
 
314
- const { unsubscribe: unsubscribe_ } = await client.transport.subscribe({
333
+ const { unsubscribe: unsubscribe_ } = await transport.subscribe({
315
334
  params: ['logs', { address, topics }],
316
335
  onData(data: any) {
317
336
  if (!active) return
@@ -0,0 +1,26 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const cyberTestnet = /*#__PURE__*/ defineChain({
4
+ id: 111_557_560,
5
+ name: 'Cyber Testnet',
6
+ nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
7
+ rpcUrls: {
8
+ default: {
9
+ http: ['https://cyber-testnet.alt.technology'],
10
+ },
11
+ },
12
+ blockExplorers: {
13
+ default: {
14
+ name: 'Blockscout',
15
+ url: 'https://cyber-testnet-explorer.alt.technology',
16
+ apiUrl: 'https://cyber-testnet-explorer.alt.technology/api',
17
+ },
18
+ },
19
+ contracts: {
20
+ multicall3: {
21
+ address: '0xffc391F0018269d4758AEA1a144772E8FB99545E',
22
+ blockCreated: 304545,
23
+ },
24
+ },
25
+ testnet: true,
26
+ })
@@ -0,0 +1,22 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const dreyerxMainnet = /*#__PURE__*/ defineChain({
4
+ id: 23451,
5
+ name: 'DreyerX Mainnet',
6
+ nativeCurrency: {
7
+ name: 'DreyerX',
8
+ symbol: 'DRX',
9
+ decimals: 18,
10
+ },
11
+ rpcUrls: {
12
+ default: {
13
+ http: ['https://rpc.dreyerx.com'],
14
+ },
15
+ },
16
+ blockExplorers: {
17
+ default: {
18
+ name: 'DreyerX Scan',
19
+ url: 'https://scan.dreyerx.com',
20
+ },
21
+ },
22
+ })
package/chains/index.ts CHANGED
@@ -52,12 +52,14 @@ export { coreDao } from './definitions/coreDao.js'
52
52
  export { cronos } from './definitions/cronos.js'
53
53
  export { cronosTestnet } from './definitions/cronosTestnet.js'
54
54
  export { crossbell } from './definitions/crossbell.js'
55
+ export { cyberTestnet } from './definitions/cyberTestnet.js'
55
56
  export { darwinia } from './definitions/darwinia.js'
56
57
  export { defichainEvm } from './definitions/defichainEvm.js'
57
58
  export { defichainEvmTestnet } from './definitions/defichainEvmTestnet.js'
58
59
  export { degen } from './definitions/degen.js'
59
60
  export { dfk } from './definitions/dfk.js'
60
61
  export { dogechain } from './definitions/dogechain.js'
62
+ export { dreyerxMainnet } from './definitions/dreyerxMainnet.js'
61
63
  export { edgeless } from './definitions/edgeless.js'
62
64
  export { edgelessTestnet } from './definitions/edgelessTestnet.js'
63
65
  export { edgeware } from './definitions/edgeware.js'
@@ -80,20 +80,23 @@ export type FallbackTransportConfig = {
80
80
  retryDelay?: TransportConfig['retryDelay'] | undefined
81
81
  }
82
82
 
83
- export type FallbackTransport = Transport<
84
- 'fallback',
85
- {
86
- onResponse: (fn: OnResponseFn) => void
87
- transports: ReturnType<Transport>[]
88
- }
89
- >
83
+ export type FallbackTransport<transports extends Transport[] = Transport[]> =
84
+ Transport<
85
+ 'fallback',
86
+ {
87
+ onResponse: (fn: OnResponseFn) => void
88
+ transports: {
89
+ [key in keyof transports]: ReturnType<transports[key]>
90
+ }
91
+ }
92
+ >
90
93
 
91
94
  export type FallbackTransportErrorType = CreateTransportErrorType | ErrorType
92
95
 
93
- export function fallback(
94
- transports_: Transport[],
96
+ export function fallback<const transports extends Transport[]>(
97
+ transports_: transports,
95
98
  config: FallbackTransportConfig = {},
96
- ): FallbackTransport {
99
+ ): FallbackTransport<transports> {
97
100
  const {
98
101
  key = 'fallback',
99
102
  name = 'Fallback',
@@ -101,7 +104,7 @@ export function fallback(
101
104
  retryCount,
102
105
  retryDelay,
103
106
  } = config
104
- return ({ chain, pollingInterval = 4_000, timeout, ...rest }) => {
107
+ return (({ chain, pollingInterval = 4_000, timeout, ...rest }) => {
105
108
  let transports = transports_
106
109
 
107
110
  let onResponse: OnResponseFn = () => {}
@@ -168,7 +171,7 @@ export function fallback(
168
171
  rankTransports({
169
172
  chain,
170
173
  interval: rankOptions.interval ?? pollingInterval,
171
- onTransports: (transports_) => (transports = transports_),
174
+ onTransports: (transports_) => (transports = transports_ as transports),
172
175
  sampleCount: rankOptions.sampleCount,
173
176
  timeout: rankOptions.timeout,
174
177
  transports,
@@ -176,7 +179,7 @@ export function fallback(
176
179
  })
177
180
  }
178
181
  return transport
179
- }
182
+ }) as FallbackTransport<transports>
180
183
  }
181
184
 
182
185
  function shouldThrow(error: Error) {
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.9.22'
1
+ export const version = '2.9.24'
@@ -0,0 +1,103 @@
1
+ import type { Client } from '../../../clients/createClient.js'
2
+ import type { Transport } from '../../../clients/transports/createTransport.js'
3
+ import { AccountNotFoundError } from '../../../errors/account.js'
4
+ import type { ErrorType } from '../../../errors/utils.js'
5
+ import type { Account, PrivateKeyAccount } from '../../../types/account.js'
6
+ import type { Chain } from '../../../types/chain.js'
7
+ import type { Hex } from '../../../types/misc.js'
8
+ import type { IsUndefined } from '../../../types/utils.js'
9
+ import type { ToAuthMessageParameters } from '../utils/toAuthMessage.js'
10
+
11
+ export type SignAuthMessageParameters<
12
+ account extends Account | undefined = Account | undefined,
13
+ > = ToAuthMessageParameters &
14
+ // TODO: Use `GetAccountParameter` when JSON-RPC method for sign auth message exists.
15
+ (IsUndefined<account> extends true
16
+ ? { account: PrivateKeyAccount }
17
+ : account extends PrivateKeyAccount
18
+ ? { account?: PrivateKeyAccount | undefined }
19
+ : { account: PrivateKeyAccount })
20
+
21
+ export type SignAuthMessageReturnType = Hex
22
+
23
+ export type SignAuthMessageErrorType = ErrorType
24
+
25
+ /**
26
+ * Calculates an [EIP-3074](https://eips.ethereum.org/EIPS/eip-3074) auth signature.
27
+ *
28
+ * With the calculated signature, you can:
29
+ * - pass it to an EIP-3074 compatible invoker contract,
30
+ * - use [`verifyAuthMessage`](/experimental/eip3074/verifyAuthMessage) to verify the signature,
31
+ * - use [`recoverAuthMessageAddress`](/experimental/eip3074/recoverAuthMessageAddress) to recover the signing address from a signature.
32
+ *
33
+ * @param client - Client to use
34
+ * @param parameters - {@link SignAuthMessageParameters}
35
+ * @returns The signed auth message. {@link SignAuthMessageReturnType}
36
+ *
37
+ * @example
38
+ * import { createWalletClient, http } from 'viem'
39
+ * import { privateKeyToAccount } from 'viem/accounts'
40
+ * import { mainnet } from 'viem/chains'
41
+ * import { signAuthMessage } from 'viem/experimental'
42
+ *
43
+ * const account = privateKeyToAccount('0x...')
44
+ *
45
+ * const client = createWalletClient({
46
+ * chain: mainnet,
47
+ * transport: http(),
48
+ * })
49
+ *
50
+ * const signature = await signAuthMessage(client, {
51
+ * account,
52
+ * chainId: 1,
53
+ * commit: keccak256('0x1234'),
54
+ * invokerAddress: '0x0000000000000000000000000000000000000000',
55
+ * nonce: 69,
56
+ * })
57
+ *
58
+ * @example
59
+ * // Account Hoisting
60
+ * import { createWalletClient, http } from 'viem'
61
+ * import { privateKeyToAccount } from 'viem/accounts'
62
+ * import { mainnet } from 'viem/chains'
63
+ * import { signAuthMessage } from 'viem/experimental'
64
+ *
65
+ * const client = createWalletClient({
66
+ * account: privateKeyToAccount('0x…'),
67
+ * chain: mainnet,
68
+ * transport: http(),
69
+ * })
70
+ *
71
+ * const signature = await signAuthMessage(client, {
72
+ * chainId: 1,
73
+ * commit: keccak256('0x1234'),
74
+ * invokerAddress: '0x0000000000000000000000000000000000000000',
75
+ * nonce: 69,
76
+ * })
77
+ */
78
+ export async function signAuthMessage<
79
+ chain extends Chain | undefined,
80
+ // TODO: Use `Account` when JSON-RPC method for sign auth message exists.
81
+ account extends Account | undefined,
82
+ >(
83
+ client: Client<Transport, chain, account>,
84
+ {
85
+ // @ts-expect-error – TODO: Remove when JSON-RPC method for sign auth message exists.
86
+ account = client.account,
87
+ chainId,
88
+ commit,
89
+ invokerAddress,
90
+ nonce,
91
+ }: SignAuthMessageParameters<account>,
92
+ ): Promise<SignAuthMessageReturnType> {
93
+ if (!account)
94
+ throw new AccountNotFoundError({
95
+ docsPath: '/experimental/eip5792/signAuthMessage',
96
+ })
97
+ return account.experimental_signAuthMessage({
98
+ chainId,
99
+ commit,
100
+ invokerAddress,
101
+ nonce,
102
+ })
103
+ }
@@ -0,0 +1,51 @@
1
+ import type { Client } from '../../../clients/createClient.js'
2
+ import type { Transport } from '../../../clients/transports/createTransport.js'
3
+ import type { Account, PrivateKeyAccount } from '../../../types/account.js'
4
+ import type { Chain } from '../../../types/chain.js'
5
+ import {
6
+ type SignAuthMessageParameters,
7
+ type SignAuthMessageReturnType,
8
+ signAuthMessage,
9
+ } from '../actions/signAuthMessage.js'
10
+
11
+ export type WalletActionsEip3074<
12
+ account extends Account | undefined = Account | undefined,
13
+ > = {
14
+ signAuthMessage: (
15
+ parameters: SignAuthMessageParameters<
16
+ account extends PrivateKeyAccount ? account : undefined
17
+ >,
18
+ ) => Promise<SignAuthMessageReturnType>
19
+ }
20
+
21
+ /**
22
+ * A suite of EIP-3074 Wallet Actions.
23
+ *
24
+ * - Docs: https://viem.sh/experimental
25
+ *
26
+ * @example
27
+ * import { createPublicClient, createWalletClient, http } from 'viem'
28
+ * import { mainnet } from 'viem/chains'
29
+ * import { walletActionsEip3074 } from 'viem/experimental'
30
+ *
31
+ * const walletClient = createWalletClient({
32
+ * chain: mainnet,
33
+ * transport: http(),
34
+ * }).extend(walletActionsEip3074())
35
+ *
36
+ * const signature = await walletClient.signAuthMessage({...})
37
+ */
38
+ export function walletActionsEip3074() {
39
+ return <
40
+ transport extends Transport,
41
+ chain extends Chain | undefined = Chain | undefined,
42
+ account extends Account | undefined = Account | undefined,
43
+ >(
44
+ client: Client<transport, chain, account>,
45
+ ): WalletActionsEip3074<account> => {
46
+ return {
47
+ signAuthMessage: (parameters) =>
48
+ signAuthMessage(client as any, parameters),
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,29 @@
1
+ import type { Address } from 'abitype'
2
+
3
+ import type { ByteArray, Hex } from '../../../types/misc.js'
4
+
5
+ import type { ErrorType } from '../../../errors/utils.js'
6
+ import { keccak256 } from '../../../utils/hash/keccak256.js'
7
+ import {
8
+ type RecoverAddressErrorType,
9
+ recoverAddress,
10
+ } from '../../../utils/signature/recoverAddress.js'
11
+ import { type ToAuthMessageParameters, toAuthMessage } from './toAuthMessage.js'
12
+
13
+ export type RecoverAuthMessageAddressParameters = ToAuthMessageParameters & {
14
+ signature: Hex | ByteArray
15
+ }
16
+
17
+ export type RecoverAuthMessageAddressReturnType = Address
18
+
19
+ export type RecoverAuthMessageAddressErrorType =
20
+ | RecoverAddressErrorType
21
+ | ErrorType
22
+
23
+ export async function recoverAuthMessageAddress({
24
+ signature,
25
+ ...parameters
26
+ }: RecoverAuthMessageAddressParameters): Promise<RecoverAuthMessageAddressReturnType> {
27
+ const hash = keccak256(toAuthMessage(parameters))
28
+ return recoverAddress({ hash, signature })
29
+ }
@@ -0,0 +1,40 @@
1
+ import { type SignErrorType, sign } from '../../../accounts/utils/sign.js'
2
+ import type { ErrorType } from '../../../errors/utils.js'
3
+ import type { Hex } from '../../../types/misc.js'
4
+ import { keccak256 } from '../../../utils/hash/keccak256.js'
5
+ import {
6
+ type SignatureToHexErrorType,
7
+ signatureToHex,
8
+ } from '../../../utils/signature/signatureToHex.js'
9
+ import {
10
+ type ToAuthMessageErrorType,
11
+ type ToAuthMessageParameters,
12
+ toAuthMessage,
13
+ } from './toAuthMessage.js'
14
+
15
+ export type SignAuthMessageParameters = ToAuthMessageParameters & {
16
+ /** The private key to sign with. */
17
+ privateKey: Hex
18
+ }
19
+
20
+ export type SignAuthMessageReturnType = Hex
21
+
22
+ export type SignAuthMessageErrorType =
23
+ | SignErrorType
24
+ | ToAuthMessageErrorType
25
+ | SignatureToHexErrorType
26
+ | ErrorType
27
+
28
+ /**
29
+ * Computes a EIP-3074 authorization signature in format: `keccak256(MAGIC || chainId || nonce || invokerAddress || commit))`.
30
+ */
31
+ export async function signAuthMessage(
32
+ parameters: SignAuthMessageParameters,
33
+ ): Promise<SignAuthMessageReturnType> {
34
+ const { privateKey } = parameters
35
+ const signature = await sign({
36
+ hash: keccak256(toAuthMessage(parameters)),
37
+ privateKey,
38
+ })
39
+ return signatureToHex(signature)
40
+ }
@@ -0,0 +1,50 @@
1
+ import type { Address } from 'abitype'
2
+ import type { ErrorType } from '../../../errors/utils.js'
3
+ import type { Hash } from '../../../types/misc.js'
4
+ import {
5
+ type EncodePackedErrorType,
6
+ encodePacked,
7
+ } from '../../../utils/abi/encodePacked.js'
8
+ import { type PadHexErrorType, padHex } from '../../../utils/data/pad.js'
9
+ import {
10
+ type NumberToHexErrorType,
11
+ numberToHex,
12
+ } from '../../../utils/encoding/toHex.js'
13
+ import { type Keccak256ErrorType } from '../../../utils/hash/keccak256.js'
14
+
15
+ export type ToAuthMessageParameters = {
16
+ chainId: number
17
+ commit: Hash
18
+ invokerAddress: Address
19
+ nonce: number
20
+ }
21
+
22
+ export type ToAuthMessageReturnType = Hash
23
+
24
+ export type ToAuthMessageErrorType =
25
+ | Keccak256ErrorType
26
+ | EncodePackedErrorType
27
+ | NumberToHexErrorType
28
+ | PadHexErrorType
29
+ | ErrorType
30
+
31
+ /**
32
+ * Returns the message to be signed for EIP-3074 authorization.
33
+ */
34
+ export function toAuthMessage({
35
+ chainId,
36
+ commit,
37
+ invokerAddress,
38
+ nonce,
39
+ }: ToAuthMessageParameters): ToAuthMessageReturnType {
40
+ return encodePacked(
41
+ ['uint8', 'bytes32', 'uint256', 'bytes32', 'bytes32'],
42
+ [
43
+ 0x04, // MAGIC
44
+ numberToHex(chainId, { size: 32 }),
45
+ BigInt(nonce),
46
+ padHex(invokerAddress, { size: 32 }),
47
+ commit,
48
+ ],
49
+ )
50
+ }