viem 2.26.3 → 2.26.5

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 (54) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/chains/definitions/lens.js +22 -0
  3. package/_cjs/chains/definitions/lens.js.map +1 -0
  4. package/_cjs/chains/index.js +9 -7
  5. package/_cjs/chains/index.js.map +1 -1
  6. package/_cjs/errors/rpc.js +113 -1
  7. package/_cjs/errors/rpc.js.map +1 -1
  8. package/_cjs/errors/version.js +1 -1
  9. package/_cjs/index.js +13 -6
  10. package/_cjs/index.js.map +1 -1
  11. package/_cjs/utils/buildRequest.js +14 -0
  12. package/_cjs/utils/buildRequest.js.map +1 -1
  13. package/_esm/account-abstraction/index.js +0 -1
  14. package/_esm/account-abstraction/index.js.map +1 -1
  15. package/_esm/chains/definitions/lens.js +19 -0
  16. package/_esm/chains/definitions/lens.js.map +1 -0
  17. package/_esm/chains/index.js +1 -0
  18. package/_esm/chains/index.js.map +1 -1
  19. package/_esm/errors/rpc.js +105 -0
  20. package/_esm/errors/rpc.js.map +1 -1
  21. package/_esm/errors/version.js +1 -1
  22. package/_esm/experimental/index.js +0 -2
  23. package/_esm/experimental/index.js.map +1 -1
  24. package/_esm/index.js +1 -5
  25. package/_esm/index.js.map +1 -1
  26. package/_esm/utils/buildRequest.js +22 -1
  27. package/_esm/utils/buildRequest.js.map +1 -1
  28. package/_types/account-abstraction/index.d.ts +1 -1
  29. package/_types/account-abstraction/index.d.ts.map +1 -1
  30. package/_types/chains/definitions/lens.d.ts +38 -0
  31. package/_types/chains/definitions/lens.d.ts.map +1 -0
  32. package/_types/chains/index.d.ts +1 -0
  33. package/_types/chains/index.d.ts.map +1 -1
  34. package/_types/errors/rpc.d.ts +92 -1
  35. package/_types/errors/rpc.d.ts.map +1 -1
  36. package/_types/errors/version.d.ts +1 -1
  37. package/_types/experimental/index.d.ts +10 -10
  38. package/_types/experimental/index.d.ts.map +1 -1
  39. package/_types/index.d.ts +5 -5
  40. package/_types/index.d.ts.map +1 -1
  41. package/_types/types/block.d.ts +20 -1
  42. package/_types/types/block.d.ts.map +1 -1
  43. package/_types/utils/buildRequest.d.ts +2 -2
  44. package/_types/utils/buildRequest.d.ts.map +1 -1
  45. package/account-abstraction/index.ts +4 -4
  46. package/chains/definitions/lens.ts +19 -0
  47. package/chains/index.ts +1 -0
  48. package/errors/rpc.ts +159 -0
  49. package/errors/version.ts +1 -1
  50. package/experimental/index.ts +10 -10
  51. package/index.ts +29 -15
  52. package/package.json +1 -1
  53. package/types/block.ts +20 -1
  54. package/utils/buildRequest.ts +46 -0
@@ -0,0 +1,19 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const lens = /*#__PURE__*/ defineChain({
4
+ id: 232,
5
+ name: 'Lens',
6
+ nativeCurrency: { name: 'GHO', symbol: 'GHO', decimals: 18 },
7
+ rpcUrls: {
8
+ default: {
9
+ http: ['https://rpc.lens.xyz'],
10
+ },
11
+ },
12
+ blockExplorers: {
13
+ default: {
14
+ name: 'Lens Block Explorer',
15
+ url: 'https://explorer.lens.xyz',
16
+ apiUrl: 'https://explorer.lens.xyz/api',
17
+ },
18
+ },
19
+ })
package/chains/index.ts CHANGED
@@ -284,6 +284,7 @@ export { kromaSepolia } from './definitions/kromaSepolia.js'
284
284
  export { l3x } from './definitions/l3x.js'
285
285
  export { l3xTestnet } from './definitions/l3xTestnet.js'
286
286
  export { lavita } from './definitions/lavita.js'
287
+ export { lens } from './definitions/lens.js'
287
288
  export { lensTestnet } from './definitions/lensTestnet.js'
288
289
  export { lightlinkPegasus } from './definitions/lightlinkPegasus.js'
289
290
  export { lightlinkPhoenix } from './definitions/lightlinkPhoenix.js'
package/errors/rpc.ts CHANGED
@@ -68,6 +68,13 @@ export type ProviderRpcErrorCode =
68
68
  | 4900 // Disconnected
69
69
  | 4901 // Chain Disconnected
70
70
  | 4902 // Chain Not Recognized
71
+ | 5700 // Unsupported non-optional capability
72
+ | 5710 // Unsupported chain id
73
+ | 5720 // Duplicate ID
74
+ | 5730 // Unknown bundle id
75
+ | 5740 // Bundle too large
76
+ | 5750 // Atomic-ready wallet rejected upgrade
77
+ | 5760 // Atomicity not supported
71
78
 
72
79
  /**
73
80
  * Error subclass implementing Ethereum Provider errors per EIP-1193.
@@ -485,6 +492,158 @@ export class SwitchChainError extends ProviderRpcError {
485
492
  }
486
493
  }
487
494
 
495
+ /**
496
+ * Subclass for an "Unsupported non-optional capability" EIP-5792 error.
497
+ *
498
+ * EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
499
+ */
500
+ export type UnsupportedNonOptionalCapabilityErrorType =
501
+ UnsupportedNonOptionalCapabilityError & {
502
+ code: 5700
503
+ name: 'UnsupportedNonOptionalCapabilityError'
504
+ }
505
+ export class UnsupportedNonOptionalCapabilityError extends ProviderRpcError {
506
+ static code = 5700 as const
507
+
508
+ constructor(cause: Error) {
509
+ super(cause, {
510
+ code: UnsupportedNonOptionalCapabilityError.code,
511
+ name: 'UnsupportedNonOptionalCapabilityError',
512
+ shortMessage:
513
+ 'This Wallet does not support a capability that was not marked as optional.',
514
+ })
515
+ }
516
+ }
517
+
518
+ /**
519
+ * Subclass for an "Unsupported chain id" EIP-5792 error.
520
+ *
521
+ * EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
522
+ */
523
+ export type UnsupportedChainIdErrorType = UnsupportedChainIdError & {
524
+ code: 5710
525
+ name: 'UnsupportedChainIdError'
526
+ }
527
+ export class UnsupportedChainIdError extends ProviderRpcError {
528
+ static code = 5710 as const
529
+
530
+ constructor(cause: Error) {
531
+ super(cause, {
532
+ code: UnsupportedChainIdError.code,
533
+ name: 'UnsupportedChainIdError',
534
+ shortMessage: 'This Wallet does not support the requested chain ID.',
535
+ })
536
+ }
537
+ }
538
+
539
+ /**
540
+ * Subclass for an "Duplicate ID" EIP-5792 error.
541
+ *
542
+ * EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
543
+ */
544
+ export type DuplicateIdErrorType = DuplicateIdError & {
545
+ code: 5720
546
+ name: 'DuplicateIdError'
547
+ }
548
+ export class DuplicateIdError extends ProviderRpcError {
549
+ static code = 5720 as const
550
+
551
+ constructor(cause: Error) {
552
+ super(cause, {
553
+ code: DuplicateIdError.code,
554
+ name: 'DuplicateIdError',
555
+ shortMessage: 'There is already a bundle submitted with this ID.',
556
+ })
557
+ }
558
+ }
559
+
560
+ /**
561
+ * Subclass for an "Unknown bundle ID" EIP-5792 error.
562
+ *
563
+ * EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
564
+ */
565
+ export type UnknownBundleIdErrorType = UnknownBundleIdError & {
566
+ code: 5730
567
+ name: 'UnknownBundleIdError'
568
+ }
569
+ export class UnknownBundleIdError extends ProviderRpcError {
570
+ static code = 5730 as const
571
+
572
+ constructor(cause: Error) {
573
+ super(cause, {
574
+ code: UnknownBundleIdError.code,
575
+ name: 'UnknownBundleIdError',
576
+ shortMessage: 'This bundle id is unknown / has not been submitted',
577
+ })
578
+ }
579
+ }
580
+
581
+ /**
582
+ * Subclass for an "Bundle too large" EIP-5792 error.
583
+ *
584
+ * EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
585
+ */
586
+ export type BundleTooLargeErrorType = BundleTooLargeError & {
587
+ code: 5740
588
+ name: 'BundleTooLargeError'
589
+ }
590
+ export class BundleTooLargeError extends ProviderRpcError {
591
+ static code = 5740 as const
592
+
593
+ constructor(cause: Error) {
594
+ super(cause, {
595
+ code: BundleTooLargeError.code,
596
+ name: 'BundleTooLargeError',
597
+ shortMessage: 'The call bundle is too large for the Wallet to process.',
598
+ })
599
+ }
600
+ }
601
+
602
+ /**
603
+ * Subclass for an "Atomic-ready wallet rejected upgrade" EIP-5792 error.
604
+ *
605
+ * EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
606
+ */
607
+ export type AtomicReadyWalletRejectedUpgradeErrorType =
608
+ AtomicReadyWalletRejectedUpgradeError & {
609
+ code: 5750
610
+ name: 'AtomicReadyWalletRejectedUpgradeError'
611
+ }
612
+ export class AtomicReadyWalletRejectedUpgradeError extends ProviderRpcError {
613
+ static code = 5750 as const
614
+
615
+ constructor(cause: Error) {
616
+ super(cause, {
617
+ code: AtomicReadyWalletRejectedUpgradeError.code,
618
+ name: 'AtomicReadyWalletRejectedUpgradeError',
619
+ shortMessage:
620
+ 'The Wallet can support atomicity after an upgrade, but the user rejected the upgrade.',
621
+ })
622
+ }
623
+ }
624
+
625
+ /**
626
+ * Subclass for an "Atomicity not supported" EIP-5792 error.
627
+ *
628
+ * EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
629
+ */
630
+ export type AtomicityNotSupportedErrorType = AtomicityNotSupportedError & {
631
+ code: 5760
632
+ name: 'AtomicityNotSupportedError'
633
+ }
634
+ export class AtomicityNotSupportedError extends ProviderRpcError {
635
+ static code = 5760 as const
636
+
637
+ constructor(cause: Error) {
638
+ super(cause, {
639
+ code: AtomicityNotSupportedError.code,
640
+ name: 'AtomicityNotSupportedError',
641
+ shortMessage:
642
+ 'The wallet does not support atomic execution but the request requires it.',
643
+ })
644
+ }
645
+ }
646
+
488
647
  /**
489
648
  * Subclass for an unknown RPC error.
490
649
  */
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.26.3'
1
+ export const version = '2.26.5'
@@ -69,25 +69,25 @@ export {
69
69
  /** @deprecated This is no longer experimental – use `import { signAuthorization } from 'viem/actions'` instead. */
70
70
  signAuthorization,
71
71
  } from '../actions/wallet/signAuthorization.js'
72
- export {
72
+ export type {
73
73
  /** @deprecated This is no longer experimental – use `import type { Authorization } from 'viem'` instead. */
74
- type Authorization,
74
+ Authorization,
75
75
  /** @deprecated This is no longer experimental – use `import type { SignedAuthorization } from 'viem'` instead. */
76
- type SignedAuthorization,
76
+ SignedAuthorization,
77
77
  /** @deprecated This is no longer experimental – use `import type { AuthorizationList } from 'viem'` instead. */
78
- type AuthorizationList,
78
+ AuthorizationList,
79
79
  /** @deprecated This is no longer experimental – use `import type { SignedAuthorizationList } from 'viem'` instead. */
80
- type SignedAuthorizationList,
80
+ SignedAuthorizationList,
81
81
  /** @deprecated This is no longer experimental – use `import type { SerializedAuthorization } from 'viem'` instead. */
82
- type SerializedAuthorization,
82
+ SerializedAuthorization,
83
83
  /** @deprecated This is no longer experimental – use `import type { SerializedAuthorizationList } from 'viem'` instead. */
84
- type SerializedAuthorizationList,
84
+ SerializedAuthorizationList,
85
85
  } from '../types/authorization.js'
86
- export {
86
+ export type {
87
87
  /** @deprecated This is no longer experimental – use `import type { RpcAuthorizationList } from 'viem'` instead. */
88
- type RpcAuthorizationList,
88
+ RpcAuthorizationList,
89
89
  /** @deprecated This is no longer experimental – use `import type { RpcAuthorization } from 'viem'` instead. */
90
- type RpcAuthorization,
90
+ RpcAuthorization,
91
91
  } from '../types/rpc.js'
92
92
  export {
93
93
  /** @deprecated This is no longer experimental – use `import type { HashAuthorizationParameters } from 'viem/utils'` instead. */
package/index.ts CHANGED
@@ -47,24 +47,24 @@ export {
47
47
  type GetContractParameters,
48
48
  type GetContractReturnType,
49
49
  } from './actions/getContract.js'
50
- export {
51
- type GetContractEventsErrorType,
52
- type GetContractEventsParameters,
53
- type GetContractEventsReturnType,
50
+ export type {
51
+ GetContractEventsErrorType,
52
+ GetContractEventsParameters,
53
+ GetContractEventsReturnType,
54
54
  } from './actions/public/getContractEvents.js'
55
- export {
56
- type GetEip712DomainErrorType,
57
- type GetEip712DomainParameters,
58
- type GetEip712DomainReturnType,
55
+ export type {
56
+ GetEip712DomainErrorType,
57
+ GetEip712DomainParameters,
58
+ GetEip712DomainReturnType,
59
59
  } from './actions/public/getEip712Domain.js'
60
- export {
61
- type AddChainErrorType,
62
- type AddChainParameters,
60
+ export type {
61
+ AddChainErrorType,
62
+ AddChainParameters,
63
63
  } from './actions/wallet/addChain.js'
64
- export {
65
- type CallErrorType,
66
- type CallParameters,
67
- type CallReturnType,
64
+ export type {
65
+ CallErrorType,
66
+ CallParameters,
67
+ CallReturnType,
68
68
  } from './actions/public/call.js'
69
69
  export type {
70
70
  CreateAccessListParameters,
@@ -769,8 +769,16 @@ export {
769
769
  type MaxFeePerGasTooLowErrorType,
770
770
  } from './errors/fee.js'
771
771
  export {
772
+ AtomicReadyWalletRejectedUpgradeError,
773
+ type AtomicReadyWalletRejectedUpgradeErrorType,
774
+ AtomicityNotSupportedError,
775
+ type AtomicityNotSupportedErrorType,
776
+ BundleTooLargeError,
777
+ type BundleTooLargeErrorType,
772
778
  ChainDisconnectedError,
773
779
  type ChainDisconnectedErrorType,
780
+ DuplicateIdError,
781
+ type DuplicateIdErrorType,
774
782
  InternalRpcError,
775
783
  type InternalRpcErrorType,
776
784
  InvalidInputRpcError,
@@ -806,8 +814,14 @@ export {
806
814
  type TransactionRejectedRpcErrorType,
807
815
  UnauthorizedProviderError,
808
816
  type UnauthorizedProviderErrorType,
817
+ UnknownBundleIdError,
818
+ type UnknownBundleIdErrorType,
809
819
  UnknownRpcError,
810
820
  type UnknownRpcErrorType,
821
+ UnsupportedChainIdError,
822
+ type UnsupportedChainIdErrorType,
823
+ UnsupportedNonOptionalCapabilityError,
824
+ type UnsupportedNonOptionalCapabilityErrorType,
811
825
  UnsupportedProviderMethodError,
812
826
  type UnsupportedProviderMethodErrorType,
813
827
  UserRejectedRequestError,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.26.3",
4
+ "version": "2.26.5",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/types/block.ts CHANGED
@@ -32,7 +32,7 @@ export type Block<
32
32
  hash: blockTag extends 'pending' ? null : Hash
33
33
  /** Logs bloom filter or `null` if pending */
34
34
  logsBloom: blockTag extends 'pending' ? null : Hex
35
- /** Address that received this block’s mining rewards */
35
+ /** Address that received this block’s mining rewards, COINBASE address */
36
36
  miner: Address
37
37
  /** Unique identifier for the block. */
38
38
  mixHash: Hash
@@ -83,8 +83,27 @@ export type BlockIdentifier<quantity = bigint> = {
83
83
  }
84
84
  )
85
85
 
86
+ /** Represents a block number in the blockchain. */
86
87
  export type BlockNumber<quantity = bigint> = quantity
87
88
 
89
+ /**
90
+ * Specifies a particular block in the blockchain.
91
+ *
92
+ * - `"latest"`: the latest proposed block
93
+ * - `"earliest"`: the earliest/genesis block – lowest numbered block the client has available
94
+ * - `"pending"`: pending state/transactions – next block built by the client on top
95
+ * of unsafe and containing the set of transactions usually taken from local mempool
96
+ * - `"safe"`: the latest safe head block – the most recent block that is safe from
97
+ * re-orgs under honest majority and certain synchronicity assumptions
98
+ * - `"finalized"`: the latest finalized block – the most recent crypto-economically secure block;
99
+ * cannot be re-orged outside of manual intervention driven by community coordination
100
+ *
101
+ * Using `pending`, while allowed, is not advised, as it may lead
102
+ * to internally inconsistent results. Use of `latest` is safe and will not
103
+ * lead to inconsistent results. Depending on the backing RPC networks caching system,
104
+ * the usage of `pending` may lead to inconsistencies as a result of an
105
+ * overly aggressive cache system. This may cause downstream errors/invalid states.
106
+ */
88
107
  export type BlockTag = 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'
89
108
 
90
109
  export type Uncle<
@@ -7,8 +7,16 @@ import {
7
7
  type WebSocketRequestErrorType,
8
8
  } from '../errors/request.js'
9
9
  import {
10
+ AtomicReadyWalletRejectedUpgradeError,
11
+ type AtomicReadyWalletRejectedUpgradeErrorType,
12
+ AtomicityNotSupportedError,
13
+ type AtomicityNotSupportedErrorType,
14
+ BundleTooLargeError,
15
+ type BundleTooLargeErrorType,
10
16
  ChainDisconnectedError,
11
17
  type ChainDisconnectedErrorType,
18
+ DuplicateIdError,
19
+ type DuplicateIdErrorType,
12
20
  InternalRpcError,
13
21
  type InternalRpcErrorType,
14
22
  InvalidInputRpcError,
@@ -43,8 +51,14 @@ import {
43
51
  type TransactionRejectedRpcErrorType,
44
52
  UnauthorizedProviderError,
45
53
  type UnauthorizedProviderErrorType,
54
+ UnknownBundleIdError,
55
+ type UnknownBundleIdErrorType,
46
56
  UnknownRpcError,
47
57
  type UnknownRpcErrorType,
58
+ UnsupportedChainIdError,
59
+ type UnsupportedChainIdErrorType,
60
+ UnsupportedNonOptionalCapabilityError,
61
+ type UnsupportedNonOptionalCapabilityErrorType,
48
62
  UnsupportedProviderMethodError,
49
63
  type UnsupportedProviderMethodErrorType,
50
64
  UserRejectedRequestError,
@@ -63,8 +77,12 @@ import type { GetSocketRpcClientErrorType } from './rpc/socket.js'
63
77
  import { stringify } from './stringify.js'
64
78
 
65
79
  export type RequestErrorType =
80
+ | AtomicityNotSupportedErrorType
81
+ | AtomicReadyWalletRejectedUpgradeErrorType
82
+ | BundleTooLargeErrorType
66
83
  | ChainDisconnectedErrorType
67
84
  | CreateBatchSchedulerErrorType
85
+ | DuplicateIdErrorType
68
86
  | HttpRequestErrorType
69
87
  | InternalRpcErrorType
70
88
  | InvalidInputRpcErrorType
@@ -85,7 +103,10 @@ export type RequestErrorType =
85
103
  | TimeoutErrorType
86
104
  | TransactionRejectedRpcErrorType
87
105
  | UnauthorizedProviderErrorType
106
+ | UnknownBundleIdErrorType
88
107
  | UnknownRpcErrorType
108
+ | UnsupportedChainIdErrorType
109
+ | UnsupportedNonOptionalCapabilityErrorType
89
110
  | UnsupportedProviderMethodErrorType
90
111
  | UserRejectedRequestErrorType
91
112
  | WebSocketRequestErrorType
@@ -170,6 +191,7 @@ export function buildRequest<request extends (args: any) => Promise<any>>(
170
191
  // -32006
171
192
  case JsonRpcVersionUnsupportedError.code:
172
193
  throw new JsonRpcVersionUnsupportedError(err)
194
+
173
195
  // 4001
174
196
  case UserRejectedRequestError.code:
175
197
  throw new UserRejectedRequestError(err)
@@ -188,10 +210,34 @@ export function buildRequest<request extends (args: any) => Promise<any>>(
188
210
  // 4902
189
211
  case SwitchChainError.code:
190
212
  throw new SwitchChainError(err)
213
+
214
+ // 5700
215
+ case UnsupportedNonOptionalCapabilityError.code:
216
+ throw new UnsupportedNonOptionalCapabilityError(err)
217
+ // 5710
218
+ case UnsupportedChainIdError.code:
219
+ throw new UnsupportedChainIdError(err)
220
+ // 5720
221
+ case DuplicateIdError.code:
222
+ throw new DuplicateIdError(err)
223
+ // 5730
224
+ case UnknownBundleIdError.code:
225
+ throw new UnknownBundleIdError(err)
226
+ // 5740
227
+ case BundleTooLargeError.code:
228
+ throw new BundleTooLargeError(err)
229
+ // 5750
230
+ case AtomicReadyWalletRejectedUpgradeError.code:
231
+ throw new AtomicReadyWalletRejectedUpgradeError(err)
232
+ // 5760
233
+ case AtomicityNotSupportedError.code:
234
+ throw new AtomicityNotSupportedError(err)
235
+
191
236
  // CAIP-25: User Rejected Error
192
237
  // https://docs.walletconnect.com/2.0/specs/clients/sign/error-codes#rejected-caip-25
193
238
  case 5000:
194
239
  throw new UserRejectedRequestError(err)
240
+
195
241
  default:
196
242
  if (err_ instanceof BaseError) throw err_
197
243
  throw new UnknownRpcError(err as Error)