viem 0.3.35 → 0.3.36

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 (87) hide show
  1. package/LICENSE +1 -1
  2. package/dist/cjs/actions/public/estimateGas.js +3 -2
  3. package/dist/cjs/actions/public/estimateGas.js.map +1 -1
  4. package/dist/cjs/errors/rpc.js +8 -2
  5. package/dist/cjs/errors/rpc.js.map +1 -1
  6. package/dist/cjs/errors/version.js +1 -1
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/types/eip1193.js +3 -3
  9. package/dist/cjs/types/eip1193.js.map +1 -1
  10. package/dist/cjs/utils/buildRequest.js.map +1 -1
  11. package/dist/esm/actions/public/estimateGas.js +3 -2
  12. package/dist/esm/actions/public/estimateGas.js.map +1 -1
  13. package/dist/esm/errors/rpc.js +8 -2
  14. package/dist/esm/errors/rpc.js.map +1 -1
  15. package/dist/esm/errors/version.js +1 -1
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/types/eip1193.js +1 -1
  18. package/dist/esm/types/eip1193.js.map +1 -1
  19. package/dist/esm/utils/buildRequest.js.map +1 -1
  20. package/dist/types/actions/public/createBlockFilter.d.ts +1 -1
  21. package/dist/types/actions/public/createContractEventFilter.d.ts +1 -1
  22. package/dist/types/actions/public/createEventFilter.d.ts +1 -1
  23. package/dist/types/actions/public/createPendingTransactionFilter.d.ts +1 -1
  24. package/dist/types/actions/public/estimateContractGas.d.ts +1 -1
  25. package/dist/types/actions/public/estimateGas.d.ts.map +1 -1
  26. package/dist/types/actions/public/getFilterChanges.d.ts +4 -4
  27. package/dist/types/actions/public/getTransaction.d.ts +1 -1
  28. package/dist/types/actions/public/getTransactionCount.d.ts +1 -1
  29. package/dist/types/actions/public/getTransactionReceipt.d.ts +1 -1
  30. package/dist/types/actions/public/multicall.d.ts +1 -1
  31. package/dist/types/actions/public/readContract.d.ts +1 -1
  32. package/dist/types/actions/public/simulateContract.d.ts +2 -2
  33. package/dist/types/actions/public/uninstallFilter.d.ts +3 -3
  34. package/dist/types/actions/public/watchContractEvent.d.ts +1 -1
  35. package/dist/types/actions/public/watchEvent.d.ts +2 -2
  36. package/dist/types/actions/test/setBlockTimestampInterval.d.ts +1 -1
  37. package/dist/types/actions/test/stopImpersonatingAccount.d.ts +1 -1
  38. package/dist/types/actions/wallet/deployContract.d.ts +1 -1
  39. package/dist/types/actions/wallet/signMessage.d.ts +2 -2
  40. package/dist/types/actions/wallet/writeContract.d.ts +3 -3
  41. package/dist/types/clients/createPublicClient.d.ts +1 -1
  42. package/dist/types/clients/createTestClient.d.ts +2 -2
  43. package/dist/types/clients/createWalletClient.d.ts +2 -2
  44. package/dist/types/clients/decorators/public.d.ts +22 -22
  45. package/dist/types/clients/decorators/test.d.ts +2 -2
  46. package/dist/types/clients/decorators/wallet.d.ts +6 -6
  47. package/dist/types/errors/rpc.d.ts +12 -8
  48. package/dist/types/errors/rpc.d.ts.map +1 -1
  49. package/dist/types/errors/version.d.ts +1 -1
  50. package/dist/types/index.d.ts +3 -3
  51. package/dist/types/index.d.ts.map +1 -1
  52. package/dist/types/types/eip1193.d.ts +7 -8
  53. package/dist/types/types/eip1193.d.ts.map +1 -1
  54. package/dist/types/utils/buildRequest.d.ts.map +1 -1
  55. package/package.json +1 -1
  56. package/src/actions/public/createBlockFilter.ts +1 -1
  57. package/src/actions/public/createContractEventFilter.ts +1 -1
  58. package/src/actions/public/createEventFilter.ts +1 -1
  59. package/src/actions/public/createPendingTransactionFilter.ts +1 -1
  60. package/src/actions/public/estimateContractGas.ts +1 -1
  61. package/src/actions/public/estimateGas.ts +3 -2
  62. package/src/actions/public/getFilterChanges.ts +4 -4
  63. package/src/actions/public/getTransaction.ts +1 -1
  64. package/src/actions/public/getTransactionCount.ts +1 -1
  65. package/src/actions/public/getTransactionReceipt.ts +1 -1
  66. package/src/actions/public/multicall.ts +1 -1
  67. package/src/actions/public/readContract.ts +1 -1
  68. package/src/actions/public/simulateContract.ts +2 -2
  69. package/src/actions/public/uninstallFilter.ts +3 -3
  70. package/src/actions/public/watchContractEvent.ts +1 -1
  71. package/src/actions/public/watchEvent.ts +2 -2
  72. package/src/actions/test/setBlockTimestampInterval.ts +1 -1
  73. package/src/actions/test/stopImpersonatingAccount.ts +1 -1
  74. package/src/actions/wallet/deployContract.ts +1 -1
  75. package/src/actions/wallet/signMessage.ts +2 -2
  76. package/src/actions/wallet/writeContract.ts +3 -3
  77. package/src/clients/createPublicClient.ts +1 -1
  78. package/src/clients/createTestClient.ts +2 -2
  79. package/src/clients/createWalletClient.ts +2 -2
  80. package/src/clients/decorators/public.ts +22 -22
  81. package/src/clients/decorators/test.ts +2 -2
  82. package/src/clients/decorators/wallet.ts +6 -6
  83. package/src/errors/rpc.ts +43 -15
  84. package/src/errors/version.ts +1 -1
  85. package/src/index.ts +24 -2
  86. package/src/types/eip1193.ts +10 -13
  87. package/src/utils/buildRequest.ts +5 -1
package/src/index.ts CHANGED
@@ -292,9 +292,11 @@ export {
292
292
  ParseRpcError,
293
293
  ProviderDisconnectedError,
294
294
  ProviderRpcError,
295
+ type ProviderRpcErrorCode,
295
296
  ResourceNotFoundRpcError,
296
297
  ResourceUnavailableRpcError,
297
298
  RpcError,
299
+ type RpcErrorCode,
298
300
  TransactionRejectedRpcError,
299
301
  SwitchChainError,
300
302
  UnauthorizedProviderError,
@@ -430,9 +432,29 @@ export {
430
432
  type BlockTag,
431
433
  type Uncle,
432
434
  } from './types/block.js'
433
- export { type ByteArray, type Hash, type Hex } from './types/misc.js'
435
+ export {
436
+ type ByteArray,
437
+ type Hash,
438
+ type Hex,
439
+ type LogTopic,
440
+ type Signature,
441
+ } from './types/misc.js'
434
442
  export type { Chain } from './types/chain.js'
435
- export type { EIP1193Provider } from './types/eip1193.js'
443
+ export type {
444
+ EIP1193Provider,
445
+ ProviderRpcError as EIP1193ProviderRpcError,
446
+ ProviderConnectInfo,
447
+ ProviderMessage,
448
+ AddEthereumChainParameter,
449
+ NetworkSync,
450
+ PublicRequests,
451
+ Requests,
452
+ SignableRequests,
453
+ WatchAssetParams,
454
+ WalletPermissionCaveat,
455
+ WalletPermission,
456
+ WalletRequests,
457
+ } from './types/eip1193.js'
436
458
  export {
437
459
  type FeeHistory,
438
460
  type FeeValues,
@@ -23,17 +23,11 @@ export type EIP1193Provider = Requests & Events
23
23
  //////////////////////////////////////////////////
24
24
  // Errors
25
25
 
26
- // rome-ignore format: no formatting
27
- export type RpcErrorCode =
28
- // https://eips.ethereum.org/EIPS/eip-1193#provider-errors
29
- | 4_001 | 4_100 | 4_200 | 4_900 | 4_901
30
- // https://eips.ethereum.org/EIPS/eip-1474#error-codes
31
- | -32700 | -32600 | -32601 | -32602 | -32603 | -32000 | -32001 | -32002 | -32003 | -32004 | -32005 | -32006
32
- export class RpcError extends Error {
33
- code: RpcErrorCode | (number & {})
26
+ export class ProviderRpcError extends Error {
27
+ code: number
34
28
  details: string
35
29
 
36
- constructor(code: RpcErrorCode | (number & {}), message: string) {
30
+ constructor(code: number, message: string) {
37
31
  super(message)
38
32
  this.code = code
39
33
  this.details = message
@@ -57,7 +51,7 @@ export type Events = {
57
51
  event: 'connect',
58
52
  listener: (connectInfo: ProviderConnectInfo) => void,
59
53
  ): void
60
- on(event: 'disconnect', listener: (error: RpcError) => void): void
54
+ on(event: 'disconnect', listener: (error: ProviderRpcError) => void): void
61
55
  on(event: 'chainChanged', listener: (chainId: string) => void): void
62
56
  on(event: 'accountsChanged', listener: (accounts: string[]) => void): void
63
57
  on(event: 'message', listener: (message: ProviderMessage) => void): void
@@ -66,7 +60,10 @@ export type Events = {
66
60
  event: 'connect',
67
61
  listener: (connectInfo: ProviderConnectInfo) => void,
68
62
  ): void
69
- removeListener(event: 'disconnect', listener: (error: RpcError) => void): void
63
+ removeListener(
64
+ event: 'disconnect',
65
+ listener: (error: ProviderRpcError) => void,
66
+ ): void
70
67
  removeListener(
71
68
  event: 'chainChanged',
72
69
  listener: (chainId: string) => void,
@@ -84,7 +81,7 @@ export type Events = {
84
81
  //////////////////////////////////////////////////
85
82
  // Provider Requests
86
83
 
87
- export type Chain = {
84
+ export type AddEthereumChainParameter = {
88
85
  /** A 0x-prefixed hexadecimal string */
89
86
  chainId: string
90
87
  /** The chain name. */
@@ -1034,7 +1031,7 @@ export type WalletRequests = {
1034
1031
  * // => { ... }
1035
1032
  */
1036
1033
  method: 'wallet_addEthereumChain'
1037
- params: [chain: Chain]
1034
+ params: [chain: AddEthereumChainParameter]
1038
1035
  }): Promise<null>
1039
1036
  request(args: {
1040
1037
  /**
@@ -12,9 +12,11 @@ import {
12
12
  MethodNotSupportedRpcError,
13
13
  ParseRpcError,
14
14
  ProviderDisconnectedError,
15
+ type ProviderRpcErrorCode,
15
16
  ResourceNotFoundRpcError,
16
17
  ResourceUnavailableRpcError,
17
18
  type RpcError,
19
+ type RpcErrorCode,
18
20
  SwitchChainError,
19
21
  TransactionRejectedRpcError,
20
22
  UnauthorizedProviderError,
@@ -66,7 +68,9 @@ export function buildRequest<TRequest extends (args: any) => Promise<any>>(
66
68
  try {
67
69
  return await request(args)
68
70
  } catch (err_) {
69
- const err = err_ as unknown as RpcError
71
+ const err = err_ as unknown as RpcError<
72
+ RpcErrorCode | ProviderRpcErrorCode
73
+ >
70
74
  if (err.code === -32700) throw new ParseRpcError(err)
71
75
  if (err.code === -32600) throw new InvalidRequestRpcError(err)
72
76
  if (err.code === -32601) throw new MethodNotFoundRpcError(err)