viem 2.9.4 → 2.9.6

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/CHANGELOG.md +20 -0
  2. package/README.md +6 -0
  3. package/_cjs/actions/public/estimateFeesPerGas.js +6 -3
  4. package/_cjs/actions/public/estimateFeesPerGas.js.map +1 -1
  5. package/_cjs/celo/chainConfig.js +2 -0
  6. package/_cjs/celo/chainConfig.js.map +1 -1
  7. package/_cjs/celo/fees.js +32 -0
  8. package/_cjs/celo/fees.js.map +1 -0
  9. package/_cjs/chains/definitions/degen.js +26 -0
  10. package/_cjs/chains/definitions/degen.js.map +1 -0
  11. package/_cjs/chains/definitions/seiDevnet.js +22 -0
  12. package/_cjs/chains/definitions/seiDevnet.js.map +1 -0
  13. package/_cjs/chains/index.js +8 -4
  14. package/_cjs/chains/index.js.map +1 -1
  15. package/_cjs/clients/transports/http.js +2 -1
  16. package/_cjs/clients/transports/http.js.map +1 -1
  17. package/_cjs/errors/version.js +1 -1
  18. package/_cjs/utils/address/getAddress.js +1 -1
  19. package/_cjs/utils/address/getAddress.js.map +1 -1
  20. package/_cjs/utils/address/isAddress.js +2 -1
  21. package/_cjs/utils/address/isAddress.js.map +1 -1
  22. package/_cjs/utils/rpc/http.js +7 -6
  23. package/_cjs/utils/rpc/http.js.map +1 -1
  24. package/_esm/actions/public/estimateFeesPerGas.js +6 -3
  25. package/_esm/actions/public/estimateFeesPerGas.js.map +1 -1
  26. package/_esm/celo/chainConfig.js +2 -0
  27. package/_esm/celo/chainConfig.js.map +1 -1
  28. package/_esm/celo/fees.js +58 -0
  29. package/_esm/celo/fees.js.map +1 -0
  30. package/_esm/chains/definitions/degen.js +23 -0
  31. package/_esm/chains/definitions/degen.js.map +1 -0
  32. package/_esm/chains/definitions/seiDevnet.js +19 -0
  33. package/_esm/chains/definitions/seiDevnet.js.map +1 -0
  34. package/_esm/chains/index.js +2 -0
  35. package/_esm/chains/index.js.map +1 -1
  36. package/_esm/clients/transports/http.js +2 -1
  37. package/_esm/clients/transports/http.js.map +1 -1
  38. package/_esm/errors/version.js +1 -1
  39. package/_esm/utils/address/getAddress.js +1 -1
  40. package/_esm/utils/address/getAddress.js.map +1 -1
  41. package/_esm/utils/address/isAddress.js +2 -1
  42. package/_esm/utils/address/isAddress.js.map +1 -1
  43. package/_esm/utils/rpc/http.js +7 -6
  44. package/_esm/utils/rpc/http.js.map +1 -1
  45. package/_types/actions/public/estimateFeesPerGas.d.ts +1 -2
  46. package/_types/actions/public/estimateFeesPerGas.d.ts.map +1 -1
  47. package/_types/actions/public/readContract.d.ts +1 -1
  48. package/_types/actions/public/readContract.d.ts.map +1 -1
  49. package/_types/actions/public/simulateContract.d.ts +1 -1
  50. package/_types/actions/public/simulateContract.d.ts.map +1 -1
  51. package/_types/celo/chainConfig.d.ts +2101 -0
  52. package/_types/celo/chainConfig.d.ts.map +1 -1
  53. package/_types/celo/fees.d.ts +4 -0
  54. package/_types/celo/fees.d.ts.map +1 -0
  55. package/_types/chains/definitions/celo.d.ts +2101 -1
  56. package/_types/chains/definitions/celo.d.ts.map +1 -1
  57. package/_types/chains/definitions/celoAlfajores.d.ts +2101 -1
  58. package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
  59. package/_types/chains/definitions/degen.d.ts +36 -0
  60. package/_types/chains/definitions/degen.d.ts.map +1 -0
  61. package/_types/chains/definitions/seiDevnet.d.ts +35 -0
  62. package/_types/chains/definitions/seiDevnet.d.ts.map +1 -0
  63. package/_types/chains/index.d.ts +2 -0
  64. package/_types/chains/index.d.ts.map +1 -1
  65. package/_types/clients/transports/http.d.ts +3 -3
  66. package/_types/clients/transports/http.d.ts.map +1 -1
  67. package/_types/errors/version.d.ts +1 -1
  68. package/_types/types/chain.d.ts +2 -1
  69. package/_types/types/chain.d.ts.map +1 -1
  70. package/_types/utils/abi/decodeFunctionResult.d.ts +1 -1
  71. package/_types/utils/abi/decodeFunctionResult.d.ts.map +1 -1
  72. package/_types/utils/abi/getAbiItem.d.ts +1 -1
  73. package/_types/utils/abi/getAbiItem.d.ts.map +1 -1
  74. package/_types/utils/address/getAddress.d.ts.map +1 -1
  75. package/_types/utils/address/isAddress.d.ts +1 -1
  76. package/_types/utils/address/isAddress.d.ts.map +1 -1
  77. package/_types/utils/rpc/http.d.ts +11 -0
  78. package/_types/utils/rpc/http.d.ts.map +1 -1
  79. package/actions/public/estimateFeesPerGas.ts +7 -4
  80. package/actions/public/readContract.ts +1 -1
  81. package/actions/public/simulateContract.ts +1 -1
  82. package/celo/chainConfig.ts +2 -0
  83. package/celo/fees.ts +92 -0
  84. package/chains/definitions/degen.ts +23 -0
  85. package/chains/definitions/seiDevnet.ts +19 -0
  86. package/chains/index.ts +2 -0
  87. package/clients/transports/http.ts +5 -3
  88. package/errors/version.ts +1 -1
  89. package/package.json +1 -1
  90. package/types/chain.ts +7 -3
  91. package/utils/abi/decodeFunctionResult.ts +1 -1
  92. package/utils/abi/getAbiItem.ts +1 -1
  93. package/utils/address/getAddress.ts +2 -1
  94. package/utils/address/isAddress.ts +3 -1
  95. package/utils/rpc/http.ts +17 -12
package/types/chain.ts CHANGED
@@ -129,13 +129,17 @@ export type ChainFees<
129
129
  * Overrides the return value in the [`estimateFeesPerGas` Action](/docs/actions/public/estimateFeesPerGas).
130
130
  */
131
131
  estimateFeesPerGas?:
132
- | ((
133
- args: ChainEstimateFeesPerGasFnParameters<formatters>,
134
- ) => Promise<EstimateFeesPerGasReturnType>)
132
+ | ChainEstimateFeesPerGasFn<formatters>
135
133
  | bigint
136
134
  | undefined
137
135
  }
138
136
 
137
+ export type ChainEstimateFeesPerGasFn<
138
+ formatters extends ChainFormatters | undefined = ChainFormatters | undefined,
139
+ > = (
140
+ args: ChainEstimateFeesPerGasFnParameters<formatters>,
141
+ ) => Promise<EstimateFeesPerGasReturnType | null>
142
+
139
143
  export type ChainFormatters = {
140
144
  /** Modifies how the Block structure is formatted & typed. */
141
145
  block?: ChainFormatter<'block'> | undefined
@@ -127,7 +127,7 @@ export type DecodeFunctionResultErrorType =
127
127
  export function decodeFunctionResult<
128
128
  const abi extends Abi | readonly unknown[],
129
129
  functionName extends ContractFunctionName<abi> | undefined = undefined,
130
- args extends ContractFunctionArgs<
130
+ const args extends ContractFunctionArgs<
131
131
  abi,
132
132
  AbiStateMutability,
133
133
  functionName extends ContractFunctionName<abi>
@@ -76,7 +76,7 @@ export type GetAbiItemReturnType<
76
76
  export function getAbiItem<
77
77
  const abi extends Abi | readonly unknown[],
78
78
  name extends AbiItemName<abi>,
79
- args extends AbiItemArgs<abi, name> | undefined = undefined,
79
+ const args extends AbiItemArgs<abi, name> | undefined = undefined,
80
80
  >(
81
81
  parameters: GetAbiItemParameters<abi, name, args>,
82
82
  ): GetAbiItemReturnType<abi, name, args> {
@@ -44,6 +44,7 @@ export type GetAddressErrorType =
44
44
  | ErrorType
45
45
 
46
46
  export function getAddress(address: string, chainId?: number): Address {
47
- if (!isAddress(address)) throw new InvalidAddressError({ address })
47
+ if (!isAddress(address, { strict: false }))
48
+ throw new InvalidAddressError({ address })
48
49
  return checksumAddress(address, chainId)
49
50
  }
@@ -20,8 +20,10 @@ export type IsAddressErrorType = ErrorType
20
20
 
21
21
  export function isAddress(
22
22
  address: string,
23
- { strict = true }: IsAddressOptions = {},
23
+ options?: IsAddressOptions | undefined,
24
24
  ): address is Address {
25
+ const { strict = true } = options ?? {}
26
+
25
27
  if (isAddressCache.has(address)) return isAddressCache.get(address)!
26
28
 
27
29
  const result = (() => {
package/utils/rpc/http.ts CHANGED
@@ -14,24 +14,28 @@ import { stringify } from '../stringify.js'
14
14
  import { idCache } from './id.js'
15
15
 
16
16
  export type HttpRpcClientOptions = {
17
- // Request configuration to pass to `fetch`.
17
+ /** Request configuration to pass to `fetch`. */
18
18
  fetchOptions?: Omit<RequestInit, 'body'> | undefined
19
- // A callback to handle the response.
19
+ /** A callback to handle the request. */
20
+ onRequest?: ((request: Request) => Promise<void> | void) | undefined
21
+ /** A callback to handle the response. */
20
22
  onResponse?: ((response: Response) => Promise<void> | void) | undefined
21
- // The timeout (in ms) for the request.
23
+ /** The timeout (in ms) for the request. */
22
24
  timeout?: number | undefined
23
25
  }
24
26
 
25
27
  export type HttpRequestParameters<
26
28
  TBody extends RpcRequest | RpcRequest[] = RpcRequest,
27
29
  > = {
28
- // The RPC request body.
30
+ /** The RPC request body. */
29
31
  body: TBody
30
- // Request configuration to pass to `fetch`.
32
+ /** Request configuration to pass to `fetch`. */
31
33
  fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined
32
- // A callback to handle the response.
34
+ /** A callback to handle the response. */
35
+ onRequest?: ((request: Request) => Promise<void> | void) | undefined
36
+ /** A callback to handle the response. */
33
37
  onResponse?: ((response: Response) => Promise<void> | void) | undefined
34
- // The timeout (in ms) for the request.
38
+ /** The timeout (in ms) for the request. */
35
39
  timeout?: HttpRpcClientOptions['timeout'] | undefined
36
40
  }
37
41
 
@@ -60,6 +64,7 @@ export function getHttpRpcClient(
60
64
  const {
61
65
  body,
62
66
  fetchOptions = {},
67
+ onRequest = options.onRequest,
63
68
  onResponse = options.onResponse,
64
69
  timeout = options.timeout ?? 10_000,
65
70
  } = params
@@ -72,7 +77,7 @@ export function getHttpRpcClient(
72
77
  try {
73
78
  const response = await withTimeout(
74
79
  async ({ signal }) => {
75
- const response = await fetch(url, {
80
+ const request = new Request(url, {
76
81
  ...fetchOptions,
77
82
  body: Array.isArray(body)
78
83
  ? stringify(
@@ -94,6 +99,8 @@ export function getHttpRpcClient(
94
99
  method: method || 'POST',
95
100
  signal: signal_ || (timeout > 0 ? signal : null),
96
101
  })
102
+ if (onRequest) await onRequest(request)
103
+ const response = await fetch(request)
97
104
  return response
98
105
  },
99
106
  {
@@ -108,11 +115,9 @@ export function getHttpRpcClient(
108
115
  let data: any
109
116
  if (
110
117
  response.headers.get('Content-Type')?.startsWith('application/json')
111
- ) {
118
+ )
112
119
  data = await response.json()
113
- } else {
114
- data = await response.text()
115
- }
120
+ else data = await response.text()
116
121
 
117
122
  if (!response.ok) {
118
123
  throw new HttpRequestError({