viem 0.0.0-portable-types-20230522163654 → 0.0.0-portable-types-20230523145621

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 (95) hide show
  1. package/dist/cjs/actions/public/estimateGas.js +3 -2
  2. package/dist/cjs/actions/public/estimateGas.js.map +1 -1
  3. package/dist/cjs/errors/rpc.js +8 -2
  4. package/dist/cjs/errors/rpc.js.map +1 -1
  5. package/dist/cjs/errors/version.js +1 -1
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/cjs/types/eip1193.js +3 -3
  8. package/dist/cjs/types/eip1193.js.map +1 -1
  9. package/dist/cjs/utils/buildRequest.js.map +1 -1
  10. package/dist/cjs/utils/transaction/prepareRequest.js +1 -2
  11. package/dist/cjs/utils/transaction/prepareRequest.js.map +1 -1
  12. package/dist/esm/actions/public/estimateGas.js +3 -2
  13. package/dist/esm/actions/public/estimateGas.js.map +1 -1
  14. package/dist/esm/errors/rpc.js +8 -2
  15. package/dist/esm/errors/rpc.js.map +1 -1
  16. package/dist/esm/errors/version.js +1 -1
  17. package/dist/esm/index.js +1 -0
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/esm/types/eip1193.js +1 -1
  20. package/dist/esm/types/eip1193.js.map +1 -1
  21. package/dist/esm/utils/buildRequest.js.map +1 -1
  22. package/dist/esm/utils/transaction/prepareRequest.js +1 -2
  23. package/dist/esm/utils/transaction/prepareRequest.js.map +1 -1
  24. package/dist/types/actions/public/createBlockFilter.d.ts +1 -1
  25. package/dist/types/actions/public/createContractEventFilter.d.ts +1 -1
  26. package/dist/types/actions/public/createEventFilter.d.ts +1 -1
  27. package/dist/types/actions/public/createPendingTransactionFilter.d.ts +1 -1
  28. package/dist/types/actions/public/estimateContractGas.d.ts +1 -1
  29. package/dist/types/actions/public/estimateGas.d.ts.map +1 -1
  30. package/dist/types/actions/public/getFilterChanges.d.ts +4 -4
  31. package/dist/types/actions/public/getTransaction.d.ts +1 -1
  32. package/dist/types/actions/public/getTransactionCount.d.ts +1 -1
  33. package/dist/types/actions/public/getTransactionReceipt.d.ts +1 -1
  34. package/dist/types/actions/public/multicall.d.ts +1 -1
  35. package/dist/types/actions/public/readContract.d.ts +2 -2
  36. package/dist/types/actions/public/readContract.d.ts.map +1 -1
  37. package/dist/types/actions/public/simulateContract.d.ts +2 -2
  38. package/dist/types/actions/public/uninstallFilter.d.ts +3 -3
  39. package/dist/types/actions/public/watchContractEvent.d.ts +1 -1
  40. package/dist/types/actions/public/watchEvent.d.ts +2 -2
  41. package/dist/types/actions/test/setBlockTimestampInterval.d.ts +1 -1
  42. package/dist/types/actions/test/stopImpersonatingAccount.d.ts +1 -1
  43. package/dist/types/actions/wallet/deployContract.d.ts +1 -1
  44. package/dist/types/actions/wallet/signMessage.d.ts +2 -2
  45. package/dist/types/actions/wallet/writeContract.d.ts +3 -3
  46. package/dist/types/clients/createPublicClient.d.ts +1 -1
  47. package/dist/types/clients/createTestClient.d.ts +2 -2
  48. package/dist/types/clients/createWalletClient.d.ts +2 -2
  49. package/dist/types/clients/decorators/public.d.ts +22 -22
  50. package/dist/types/clients/decorators/test.d.ts +2 -2
  51. package/dist/types/clients/decorators/wallet.d.ts +6 -6
  52. package/dist/types/errors/rpc.d.ts +12 -8
  53. package/dist/types/errors/rpc.d.ts.map +1 -1
  54. package/dist/types/errors/version.d.ts +1 -1
  55. package/dist/types/index.d.ts +3 -2
  56. package/dist/types/index.d.ts.map +1 -1
  57. package/dist/types/types/eip1193.d.ts +7 -8
  58. package/dist/types/types/eip1193.d.ts.map +1 -1
  59. package/dist/types/utils/buildRequest.d.ts.map +1 -1
  60. package/dist/types/utils/transaction/prepareRequest.d.ts +1 -1
  61. package/dist/types/utils/transaction/prepareRequest.d.ts.map +1 -1
  62. package/package.json +1 -1
  63. package/src/actions/public/createBlockFilter.ts +1 -1
  64. package/src/actions/public/createContractEventFilter.ts +1 -1
  65. package/src/actions/public/createEventFilter.ts +1 -1
  66. package/src/actions/public/createPendingTransactionFilter.ts +1 -1
  67. package/src/actions/public/estimateContractGas.ts +1 -1
  68. package/src/actions/public/estimateGas.ts +3 -2
  69. package/src/actions/public/getFilterChanges.ts +4 -4
  70. package/src/actions/public/getTransaction.ts +1 -1
  71. package/src/actions/public/getTransactionCount.ts +1 -1
  72. package/src/actions/public/getTransactionReceipt.ts +1 -1
  73. package/src/actions/public/multicall.ts +1 -1
  74. package/src/actions/public/readContract.ts +2 -2
  75. package/src/actions/public/simulateContract.ts +2 -2
  76. package/src/actions/public/uninstallFilter.ts +3 -3
  77. package/src/actions/public/watchContractEvent.ts +1 -1
  78. package/src/actions/public/watchEvent.ts +2 -2
  79. package/src/actions/test/setBlockTimestampInterval.ts +1 -1
  80. package/src/actions/test/stopImpersonatingAccount.ts +1 -1
  81. package/src/actions/wallet/deployContract.ts +1 -1
  82. package/src/actions/wallet/signMessage.ts +2 -2
  83. package/src/actions/wallet/writeContract.ts +3 -3
  84. package/src/clients/createPublicClient.ts +1 -1
  85. package/src/clients/createTestClient.ts +2 -2
  86. package/src/clients/createWalletClient.ts +2 -2
  87. package/src/clients/decorators/public.ts +22 -22
  88. package/src/clients/decorators/test.ts +2 -2
  89. package/src/clients/decorators/wallet.ts +6 -6
  90. package/src/errors/rpc.ts +42 -15
  91. package/src/errors/version.ts +1 -1
  92. package/src/index.ts +8 -3
  93. package/src/types/eip1193.ts +10 -13
  94. package/src/utils/buildRequest.ts +5 -1
  95. package/src/utils/transaction/prepareRequest.ts +1 -2
@@ -390,7 +390,7 @@ export type TestActions = {
390
390
  */
391
391
  setBlockGasLimit: (args: SetBlockGasLimitParameters) => Promise<void>
392
392
  /**
393
- * Similar to [`increaseTime`](https://viem.sh/docs/actions/test/increaseTime), but sets a block timestamp `interval`. The timestamp of future blocks will be computed as `lastBlock_timestamp` + `interval`.
393
+ * Similar to [`increaseTime`](https://viem.sh/docs/actions/test/increaseTime.html), but sets a block timestamp `interval`. The timestamp of future blocks will be computed as `lastBlock_timestamp` + `interval`.
394
394
  *
395
395
  * - Docs: https://viem.sh/docs/actions/test/setBlockTimestampInterval.html
396
396
  *
@@ -641,7 +641,7 @@ export type TestActions = {
641
641
  */
642
642
  snapshot: () => Promise<Quantity>
643
643
  /**
644
- * Stop impersonating an account after having previously used [`impersonateAccount`](https://viem.sh/docs/actions/test/impersonateAccount).
644
+ * Stop impersonating an account after having previously used [`impersonateAccount`](https://viem.sh/docs/actions/test/impersonateAccount.html).
645
645
  *
646
646
  * - Docs: https://viem.sh/docs/actions/test/stopImpersonatingAccount.html
647
647
  *
@@ -93,7 +93,7 @@ export type WalletActions<
93
93
  * - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/deploying-contracts
94
94
  *
95
95
  * @param args - {@link DeployContractParameters}
96
- * @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
96
+ * @returns The [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) hash. {@link DeployContractReturnType}
97
97
  *
98
98
  * @example
99
99
  * import { createWalletClient, http } from 'viem'
@@ -276,8 +276,8 @@ export type WalletActions<
276
276
  * - Local Accounts: Signs locally. No JSON-RPC request.
277
277
  *
278
278
  * With the calculated signature, you can:
279
- * - use [`verifyMessage`](https://viem.sh/docs/utilities/verifyMessage) to verify the signature,
280
- * - use [`recoverMessageAddress`](https://viem.sh/docs/utilities/recoverMessageAddress) to recover the signing address from a signature.
279
+ * - use [`verifyMessage`](https://viem.sh/docs/utilities/verifyMessage.html) to verify the signature,
280
+ * - use [`recoverMessageAddress`](https://viem.sh/docs/utilities/recoverMessageAddress.html) to recover the signing address from a signature.
281
281
  *
282
282
  * @param args - {@link SignMessageParameters}
283
283
  * @returns The signed message. {@link SignMessageReturnType}
@@ -467,14 +467,14 @@ export type WalletActions<
467
467
  * - Docs: https://viem.sh/docs/contract/writeContract.html
468
468
  * - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/writing-to-contracts
469
469
  *
470
- * A "write" function on a Solidity contract modifies the state of the blockchain. These types of functions require gas to be executed, and hence a [Transaction](https://viem.sh/docs/glossary/terms) is needed to be broadcast in order to change the state.
470
+ * A "write" function on a Solidity contract modifies the state of the blockchain. These types of functions require gas to be executed, and hence a [Transaction](https://viem.sh/docs/glossary/terms.html) is needed to be broadcast in order to change the state.
471
471
  *
472
- * Internally, uses a [Wallet Client](https://viem.sh/docs/clients/wallet) to call the [`sendTransaction` action](https://viem.sh/docs/actions/wallet/sendTransaction) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData).
472
+ * Internally, uses a [Wallet Client](https://viem.sh/docs/clients/wallet.html) to call the [`sendTransaction` action](https://viem.sh/docs/actions/wallet/sendTransaction.html) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData.html).
473
473
  *
474
474
  * __Warning: The `write` internally sends a transaction – it does not validate if the contract write will succeed (the contract may throw an error). It is highly recommended to [simulate the contract write with `contract.simulate`](https://viem.sh/docs/contract/writeContract.html#usage) before you execute it.__
475
475
  *
476
476
  * @param args - {@link WriteContractParameters}
477
- * @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms#hash). {@link WriteContractReturnType}
477
+ * @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms.html#hash). {@link WriteContractReturnType}
478
478
  *
479
479
  * @example
480
480
  * import { createWalletClient, custom, parseAbi } from 'viem'
package/src/errors/rpc.ts CHANGED
@@ -1,10 +1,27 @@
1
+ import type { Prettify } from '../types/utils.js'
1
2
  import { BaseError } from './base.js'
2
3
  import { RpcRequestError } from './request.js'
3
4
 
4
5
  const unknownErrorCode = -1
5
6
 
6
- type RpcErrorOptions = {
7
- code?: number
7
+ export type RpcErrorCode =
8
+ | -1
9
+ | -32700 // Parse error
10
+ | -32600 // Invalid request
11
+ | -32601 // Method not found
12
+ | -32602 // Invalid params
13
+ | -32603 // Internal error
14
+ | -32000 // Invalid input
15
+ | -32001 // Resource not found
16
+ | -32002 // Resource unavailable
17
+ | -32003 // Transaction rejected
18
+ | -32004 // Method not supported
19
+ | -32005 // Limit exceeded
20
+ | -32006 // JSON-RPC version not supported
21
+ | -32042 // Method not found
22
+
23
+ type RpcErrorOptions<TCode extends number = RpcErrorCode> = {
24
+ code?: TCode
8
25
  docsPath?: string
9
26
  metaMessages?: string[]
10
27
  shortMessage: string
@@ -15,17 +32,13 @@ type RpcErrorOptions = {
15
32
  *
16
33
  * - EIP https://eips.ethereum.org/EIPS/eip-1474
17
34
  */
18
- export class RpcError extends BaseError {
19
- code: number
35
+ export class RpcError<TCode extends number = RpcErrorCode> extends BaseError {
36
+ override name = 'RpcError'
37
+ code: TCode
20
38
 
21
39
  constructor(
22
40
  cause: Error,
23
- {
24
- code = unknownErrorCode,
25
- docsPath,
26
- metaMessages,
27
- shortMessage,
28
- }: RpcErrorOptions,
41
+ { code, docsPath, metaMessages, shortMessage }: RpcErrorOptions<TCode>,
29
42
  ) {
30
43
  super(shortMessage, {
31
44
  cause,
@@ -34,25 +47,39 @@ export class RpcError extends BaseError {
34
47
  metaMessages || (cause as { metaMessages?: string[] })?.metaMessages,
35
48
  })
36
49
  this.name = cause.name
37
- this.code = cause instanceof RpcRequestError ? cause.code : code
50
+ this.code = (
51
+ cause instanceof RpcRequestError ? cause.code : code ?? unknownErrorCode
52
+ ) as TCode
38
53
  }
39
54
  }
40
55
 
56
+ export type ProviderRpcErrorCode =
57
+ | 4001 // User Rejected Request
58
+ | 4100 // Unauthorized
59
+ | 4200 // Unsupported Method
60
+ | 4900 // Disconnected
61
+ | 4901 // Chain Disconnected
62
+ | 4902 // Chain Not Recongnized
63
+
41
64
  /**
42
65
  * Error subclass implementing Ethereum Provider errors per EIP-1193.
43
66
  *
44
67
  * - EIP https://eips.ethereum.org/EIPS/eip-1193
45
68
  */
46
- export class ProviderRpcError<T = undefined> extends RpcError {
69
+ export class ProviderRpcError<
70
+ T = undefined,
71
+ > extends RpcError<ProviderRpcErrorCode> {
47
72
  override name = 'ProviderRpcError'
48
73
 
49
74
  data?: T
50
75
 
51
76
  constructor(
52
77
  cause: Error,
53
- options: RpcErrorOptions & {
54
- data?: T
55
- },
78
+ options: Prettify<
79
+ RpcErrorOptions<ProviderRpcErrorCode> & {
80
+ data?: T
81
+ }
82
+ >,
56
83
  ) {
57
84
  super(cause, options)
58
85
 
@@ -1 +1 @@
1
- export const version = '0.3.33'
1
+ export const version = '0.3.35'
package/src/index.ts CHANGED
@@ -23,6 +23,10 @@ export {
23
23
  type DeployContractReturnType,
24
24
  } from './actions/wallet/deployContract.js'
25
25
  export type { DropTransactionParameters } from './actions/test/dropTransaction.js'
26
+ export {
27
+ type EstimateContractGasParameters,
28
+ type EstimateContractGasReturnType,
29
+ } from './actions/public/estimateContractGas.js'
26
30
  export {
27
31
  type EstimateGasParameters,
28
32
  type EstimateGasReturnType,
@@ -288,9 +292,11 @@ export {
288
292
  ParseRpcError,
289
293
  ProviderDisconnectedError,
290
294
  ProviderRpcError,
295
+ type ProviderRpcErrorCode,
291
296
  ResourceNotFoundRpcError,
292
297
  ResourceUnavailableRpcError,
293
298
  RpcError,
299
+ type RpcErrorCode,
294
300
  TransactionRejectedRpcError,
295
301
  SwitchChainError,
296
302
  UnauthorizedProviderError,
@@ -436,11 +442,10 @@ export {
436
442
  export type { Chain } from './types/chain.js'
437
443
  export type {
438
444
  EIP1193Provider,
439
- RpcErrorCode,
440
- RpcError as RpcError_,
445
+ ProviderRpcError as EIP1193ProviderRpcError,
441
446
  ProviderConnectInfo,
442
447
  ProviderMessage,
443
- Chain as Chain_,
448
+ AddEthereumChainParameter,
444
449
  NetworkSync,
445
450
  PublicRequests,
446
451
  Requests,
@@ -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)
@@ -17,7 +17,6 @@ import { AccountNotFoundError } from '../../errors/account.js'
17
17
  import { BaseError } from '../../errors/base.js'
18
18
  import type { GetAccountParameter } from '../../types/account.js'
19
19
  import type { Chain } from '../../types/chain.js'
20
- import { parseGwei } from '../unit/parseGwei.js'
21
20
 
22
21
  import { assertRequest } from './assertRequest.js'
23
22
 
@@ -43,7 +42,7 @@ export type PrepareRequestReturnType<
43
42
  nonce: SendTransactionParameters['nonce']
44
43
  }
45
44
 
46
- export const defaultTip = parseGwei('1.5')
45
+ export const defaultTip = 1_500_000_000n // 1.5 gwei
47
46
 
48
47
  export async function prepareRequest<
49
48
  TChain extends Chain | undefined,