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.
- package/CHANGELOG.md +20 -0
- package/README.md +6 -0
- package/_cjs/actions/public/estimateFeesPerGas.js +6 -3
- package/_cjs/actions/public/estimateFeesPerGas.js.map +1 -1
- package/_cjs/celo/chainConfig.js +2 -0
- package/_cjs/celo/chainConfig.js.map +1 -1
- package/_cjs/celo/fees.js +32 -0
- package/_cjs/celo/fees.js.map +1 -0
- package/_cjs/chains/definitions/degen.js +26 -0
- package/_cjs/chains/definitions/degen.js.map +1 -0
- package/_cjs/chains/definitions/seiDevnet.js +22 -0
- package/_cjs/chains/definitions/seiDevnet.js.map +1 -0
- package/_cjs/chains/index.js +8 -4
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/transports/http.js +2 -1
- package/_cjs/clients/transports/http.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/utils/address/getAddress.js +1 -1
- package/_cjs/utils/address/getAddress.js.map +1 -1
- package/_cjs/utils/address/isAddress.js +2 -1
- package/_cjs/utils/address/isAddress.js.map +1 -1
- package/_cjs/utils/rpc/http.js +7 -6
- package/_cjs/utils/rpc/http.js.map +1 -1
- package/_esm/actions/public/estimateFeesPerGas.js +6 -3
- package/_esm/actions/public/estimateFeesPerGas.js.map +1 -1
- package/_esm/celo/chainConfig.js +2 -0
- package/_esm/celo/chainConfig.js.map +1 -1
- package/_esm/celo/fees.js +58 -0
- package/_esm/celo/fees.js.map +1 -0
- package/_esm/chains/definitions/degen.js +23 -0
- package/_esm/chains/definitions/degen.js.map +1 -0
- package/_esm/chains/definitions/seiDevnet.js +19 -0
- package/_esm/chains/definitions/seiDevnet.js.map +1 -0
- package/_esm/chains/index.js +2 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/transports/http.js +2 -1
- package/_esm/clients/transports/http.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/utils/address/getAddress.js +1 -1
- package/_esm/utils/address/getAddress.js.map +1 -1
- package/_esm/utils/address/isAddress.js +2 -1
- package/_esm/utils/address/isAddress.js.map +1 -1
- package/_esm/utils/rpc/http.js +7 -6
- package/_esm/utils/rpc/http.js.map +1 -1
- package/_types/actions/public/estimateFeesPerGas.d.ts +1 -2
- package/_types/actions/public/estimateFeesPerGas.d.ts.map +1 -1
- package/_types/actions/public/readContract.d.ts +1 -1
- package/_types/actions/public/readContract.d.ts.map +1 -1
- package/_types/actions/public/simulateContract.d.ts +1 -1
- package/_types/actions/public/simulateContract.d.ts.map +1 -1
- package/_types/celo/chainConfig.d.ts +2101 -0
- package/_types/celo/chainConfig.d.ts.map +1 -1
- package/_types/celo/fees.d.ts +4 -0
- package/_types/celo/fees.d.ts.map +1 -0
- package/_types/chains/definitions/celo.d.ts +2101 -1
- package/_types/chains/definitions/celo.d.ts.map +1 -1
- package/_types/chains/definitions/celoAlfajores.d.ts +2101 -1
- package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
- package/_types/chains/definitions/degen.d.ts +36 -0
- package/_types/chains/definitions/degen.d.ts.map +1 -0
- package/_types/chains/definitions/seiDevnet.d.ts +35 -0
- package/_types/chains/definitions/seiDevnet.d.ts.map +1 -0
- package/_types/chains/index.d.ts +2 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/transports/http.d.ts +3 -3
- package/_types/clients/transports/http.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/types/chain.d.ts +2 -1
- package/_types/types/chain.d.ts.map +1 -1
- package/_types/utils/abi/decodeFunctionResult.d.ts +1 -1
- package/_types/utils/abi/decodeFunctionResult.d.ts.map +1 -1
- package/_types/utils/abi/getAbiItem.d.ts +1 -1
- package/_types/utils/abi/getAbiItem.d.ts.map +1 -1
- package/_types/utils/address/getAddress.d.ts.map +1 -1
- package/_types/utils/address/isAddress.d.ts +1 -1
- package/_types/utils/address/isAddress.d.ts.map +1 -1
- package/_types/utils/rpc/http.d.ts +11 -0
- package/_types/utils/rpc/http.d.ts.map +1 -1
- package/actions/public/estimateFeesPerGas.ts +7 -4
- package/actions/public/readContract.ts +1 -1
- package/actions/public/simulateContract.ts +1 -1
- package/celo/chainConfig.ts +2 -0
- package/celo/fees.ts +92 -0
- package/chains/definitions/degen.ts +23 -0
- package/chains/definitions/seiDevnet.ts +19 -0
- package/chains/index.ts +2 -0
- package/clients/transports/http.ts +5 -3
- package/errors/version.ts +1 -1
- package/package.json +1 -1
- package/types/chain.ts +7 -3
- package/utils/abi/decodeFunctionResult.ts +1 -1
- package/utils/abi/getAbiItem.ts +1 -1
- package/utils/address/getAddress.ts +2 -1
- package/utils/address/isAddress.ts +3 -1
- 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>
|
package/utils/abi/getAbiItem.ts
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
17
|
+
/** Request configuration to pass to `fetch`. */
|
18
18
|
fetchOptions?: Omit<RequestInit, 'body'> | undefined
|
19
|
-
|
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
|
-
|
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
|
-
|
30
|
+
/** The RPC request body. */
|
29
31
|
body: TBody
|
30
|
-
|
32
|
+
/** Request configuration to pass to `fetch`. */
|
31
33
|
fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined
|
32
|
-
|
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
|
-
|
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
|
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
|
-
|
114
|
-
data = await response.text()
|
115
|
-
}
|
120
|
+
else data = await response.text()
|
116
121
|
|
117
122
|
if (!response.ok) {
|
118
123
|
throw new HttpRequestError({
|