viem 0.3.34 → 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.
- package/LICENSE +1 -1
- package/dist/cjs/actions/public/estimateGas.js +3 -2
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/errors/rpc.js +8 -2
- package/dist/cjs/errors/rpc.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/eip1193.js +3 -3
- package/dist/cjs/types/eip1193.js.map +1 -1
- package/dist/cjs/utils/buildRequest.js.map +1 -1
- package/dist/esm/actions/public/estimateGas.js +3 -2
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/errors/rpc.js +8 -2
- package/dist/esm/errors/rpc.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/eip1193.js +1 -1
- package/dist/esm/types/eip1193.js.map +1 -1
- package/dist/esm/utils/buildRequest.js.map +1 -1
- package/dist/types/actions/public/createBlockFilter.d.ts +1 -1
- package/dist/types/actions/public/createContractEventFilter.d.ts +1 -1
- package/dist/types/actions/public/createEventFilter.d.ts +1 -1
- package/dist/types/actions/public/createPendingTransactionFilter.d.ts +1 -1
- package/dist/types/actions/public/estimateContractGas.d.ts +1 -1
- package/dist/types/actions/public/estimateGas.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterChanges.d.ts +4 -4
- package/dist/types/actions/public/getTransaction.d.ts +1 -1
- package/dist/types/actions/public/getTransactionCount.d.ts +1 -1
- package/dist/types/actions/public/getTransactionReceipt.d.ts +1 -1
- package/dist/types/actions/public/multicall.d.ts +1 -1
- package/dist/types/actions/public/readContract.d.ts +2 -2
- package/dist/types/actions/public/readContract.d.ts.map +1 -1
- package/dist/types/actions/public/simulateContract.d.ts +2 -2
- package/dist/types/actions/public/uninstallFilter.d.ts +3 -3
- package/dist/types/actions/public/watchContractEvent.d.ts +1 -1
- package/dist/types/actions/public/watchEvent.d.ts +2 -2
- package/dist/types/actions/test/setBlockTimestampInterval.d.ts +1 -1
- package/dist/types/actions/test/stopImpersonatingAccount.d.ts +1 -1
- package/dist/types/actions/wallet/deployContract.d.ts +1 -1
- package/dist/types/actions/wallet/signMessage.d.ts +2 -2
- package/dist/types/actions/wallet/writeContract.d.ts +3 -3
- package/dist/types/clients/createPublicClient.d.ts +1 -1
- package/dist/types/clients/createTestClient.d.ts +2 -2
- package/dist/types/clients/createWalletClient.d.ts +2 -2
- package/dist/types/clients/decorators/public.d.ts +22 -22
- package/dist/types/clients/decorators/test.d.ts +2 -2
- package/dist/types/clients/decorators/wallet.d.ts +6 -6
- package/dist/types/errors/rpc.d.ts +12 -8
- package/dist/types/errors/rpc.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/eip1193.d.ts +7 -8
- package/dist/types/types/eip1193.d.ts.map +1 -1
- package/dist/types/utils/buildRequest.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/actions/public/createBlockFilter.ts +1 -1
- package/src/actions/public/createContractEventFilter.ts +1 -1
- package/src/actions/public/createEventFilter.ts +1 -1
- package/src/actions/public/createPendingTransactionFilter.ts +1 -1
- package/src/actions/public/estimateContractGas.ts +1 -1
- package/src/actions/public/estimateGas.ts +3 -2
- package/src/actions/public/getFilterChanges.ts +4 -4
- package/src/actions/public/getTransaction.ts +1 -1
- package/src/actions/public/getTransactionCount.ts +1 -1
- package/src/actions/public/getTransactionReceipt.ts +1 -1
- package/src/actions/public/multicall.ts +1 -1
- package/src/actions/public/readContract.ts +2 -2
- package/src/actions/public/simulateContract.ts +2 -2
- package/src/actions/public/uninstallFilter.ts +3 -3
- package/src/actions/public/watchContractEvent.ts +1 -1
- package/src/actions/public/watchEvent.ts +2 -2
- package/src/actions/test/setBlockTimestampInterval.ts +1 -1
- package/src/actions/test/stopImpersonatingAccount.ts +1 -1
- package/src/actions/wallet/deployContract.ts +1 -1
- package/src/actions/wallet/signMessage.ts +2 -2
- package/src/actions/wallet/writeContract.ts +3 -3
- package/src/clients/createPublicClient.ts +1 -1
- package/src/clients/createTestClient.ts +2 -2
- package/src/clients/createWalletClient.ts +2 -2
- package/src/clients/decorators/public.ts +22 -22
- package/src/clients/decorators/test.ts +2 -2
- package/src/clients/decorators/wallet.ts +6 -6
- package/src/errors/rpc.ts +43 -15
- package/src/errors/version.ts +1 -1
- package/src/index.ts +24 -2
- package/src/types/eip1193.ts +10 -13
- package/src/utils/buildRequest.ts +5 -1
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
|
7
|
-
|
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 | (number & {})
|
8
25
|
docsPath?: string
|
9
26
|
metaMessages?: string[]
|
10
27
|
shortMessage: string
|
@@ -15,17 +32,14 @@ type RpcErrorOptions = {
|
|
15
32
|
*
|
16
33
|
* - EIP https://eips.ethereum.org/EIPS/eip-1474
|
17
34
|
*/
|
18
|
-
export class RpcError extends BaseError {
|
19
|
-
|
35
|
+
export class RpcError<TCode extends number = RpcErrorCode> extends BaseError {
|
36
|
+
override name = 'RpcError'
|
37
|
+
|
38
|
+
code: TCode | (number & {})
|
20
39
|
|
21
40
|
constructor(
|
22
41
|
cause: Error,
|
23
|
-
{
|
24
|
-
code = unknownErrorCode,
|
25
|
-
docsPath,
|
26
|
-
metaMessages,
|
27
|
-
shortMessage,
|
28
|
-
}: RpcErrorOptions,
|
42
|
+
{ code, docsPath, metaMessages, shortMessage }: RpcErrorOptions<TCode>,
|
29
43
|
) {
|
30
44
|
super(shortMessage, {
|
31
45
|
cause,
|
@@ -34,25 +48,39 @@ export class RpcError extends BaseError {
|
|
34
48
|
metaMessages || (cause as { metaMessages?: string[] })?.metaMessages,
|
35
49
|
})
|
36
50
|
this.name = cause.name
|
37
|
-
this.code =
|
51
|
+
this.code = (
|
52
|
+
cause instanceof RpcRequestError ? cause.code : code ?? unknownErrorCode
|
53
|
+
) as TCode
|
38
54
|
}
|
39
55
|
}
|
40
56
|
|
57
|
+
export type ProviderRpcErrorCode =
|
58
|
+
| 4001 // User Rejected Request
|
59
|
+
| 4100 // Unauthorized
|
60
|
+
| 4200 // Unsupported Method
|
61
|
+
| 4900 // Disconnected
|
62
|
+
| 4901 // Chain Disconnected
|
63
|
+
| 4902 // Chain Not Recongnized
|
64
|
+
|
41
65
|
/**
|
42
66
|
* Error subclass implementing Ethereum Provider errors per EIP-1193.
|
43
67
|
*
|
44
68
|
* - EIP https://eips.ethereum.org/EIPS/eip-1193
|
45
69
|
*/
|
46
|
-
export class ProviderRpcError<
|
70
|
+
export class ProviderRpcError<
|
71
|
+
T = undefined,
|
72
|
+
> extends RpcError<ProviderRpcErrorCode> {
|
47
73
|
override name = 'ProviderRpcError'
|
48
74
|
|
49
75
|
data?: T
|
50
76
|
|
51
77
|
constructor(
|
52
78
|
cause: Error,
|
53
|
-
options:
|
54
|
-
|
55
|
-
|
79
|
+
options: Prettify<
|
80
|
+
RpcErrorOptions<ProviderRpcErrorCode> & {
|
81
|
+
data?: T
|
82
|
+
}
|
83
|
+
>,
|
56
84
|
) {
|
57
85
|
super(cause, options)
|
58
86
|
|
package/src/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '0.3.
|
1
|
+
export const version = '0.3.36'
|
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 {
|
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 {
|
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,
|
package/src/types/eip1193.ts
CHANGED
@@ -23,17 +23,11 @@ export type EIP1193Provider = Requests & Events
|
|
23
23
|
//////////////////////////////////////////////////
|
24
24
|
// Errors
|
25
25
|
|
26
|
-
|
27
|
-
|
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:
|
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:
|
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(
|
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
|
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:
|
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)
|