viem 2.9.6 → 2.9.8

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 (88) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/_cjs/chains/definitions/degen.js +1 -0
  3. package/_cjs/chains/definitions/degen.js.map +1 -1
  4. package/_cjs/chains/definitions/zkSyncInMemoryNode.js +2 -0
  5. package/_cjs/chains/definitions/zkSyncInMemoryNode.js.map +1 -1
  6. package/_cjs/chains/definitions/zkSyncLocalNode.js +2 -0
  7. package/_cjs/chains/definitions/zkSyncLocalNode.js.map +1 -1
  8. package/_cjs/errors/version.js +1 -1
  9. package/_cjs/experimental/actions/getCallsStatus.js +23 -0
  10. package/_cjs/experimental/actions/getCallsStatus.js.map +1 -0
  11. package/_cjs/experimental/actions/getCapabilities.js +14 -0
  12. package/_cjs/experimental/actions/getCapabilities.js.map +1 -0
  13. package/_cjs/experimental/actions/sendCalls.js +42 -0
  14. package/_cjs/experimental/actions/sendCalls.js.map +1 -0
  15. package/_cjs/experimental/actions/writeContracts.js +23 -0
  16. package/_cjs/experimental/actions/writeContracts.js.map +1 -0
  17. package/_cjs/experimental/decorators/eip5792.js +19 -0
  18. package/_cjs/experimental/decorators/eip5792.js.map +1 -0
  19. package/_cjs/experimental/index.js +14 -0
  20. package/_cjs/experimental/index.js.map +1 -0
  21. package/_cjs/index.js.map +1 -1
  22. package/_cjs/utils/formatters/transactionReceipt.js +3 -3
  23. package/_cjs/utils/formatters/transactionReceipt.js.map +1 -1
  24. package/_esm/chains/definitions/degen.js +1 -0
  25. package/_esm/chains/definitions/degen.js.map +1 -1
  26. package/_esm/chains/definitions/zkSyncInMemoryNode.js +2 -0
  27. package/_esm/chains/definitions/zkSyncInMemoryNode.js.map +1 -1
  28. package/_esm/chains/definitions/zkSyncLocalNode.js +2 -0
  29. package/_esm/chains/definitions/zkSyncLocalNode.js.map +1 -1
  30. package/_esm/errors/version.js +1 -1
  31. package/_esm/experimental/actions/getCallsStatus.js +39 -0
  32. package/_esm/experimental/actions/getCallsStatus.js.map +1 -0
  33. package/_esm/experimental/actions/getCapabilities.js +30 -0
  34. package/_esm/experimental/actions/getCapabilities.js.map +1 -0
  35. package/_esm/experimental/actions/sendCalls.js +70 -0
  36. package/_esm/experimental/actions/sendCalls.js.map +1 -0
  37. package/_esm/experimental/actions/writeContracts.js +62 -0
  38. package/_esm/experimental/actions/writeContracts.js.map +1 -0
  39. package/_esm/experimental/decorators/eip5792.js +32 -0
  40. package/_esm/experimental/decorators/eip5792.js.map +1 -0
  41. package/_esm/experimental/index.js +6 -0
  42. package/_esm/experimental/index.js.map +1 -0
  43. package/_esm/index.js.map +1 -1
  44. package/_esm/utils/formatters/transactionReceipt.js +2 -2
  45. package/_esm/utils/formatters/transactionReceipt.js.map +1 -1
  46. package/_types/chains/definitions/degen.d.ts +1 -0
  47. package/_types/chains/definitions/degen.d.ts.map +1 -1
  48. package/_types/chains/definitions/zkSyncInMemoryNode.d.ts +1278 -3
  49. package/_types/chains/definitions/zkSyncInMemoryNode.d.ts.map +1 -1
  50. package/_types/chains/definitions/zkSyncLocalNode.d.ts +1278 -3
  51. package/_types/chains/definitions/zkSyncLocalNode.d.ts.map +1 -1
  52. package/_types/errors/version.d.ts +1 -1
  53. package/_types/experimental/actions/getCallsStatus.d.ts +35 -0
  54. package/_types/experimental/actions/getCallsStatus.d.ts.map +1 -0
  55. package/_types/experimental/actions/getCapabilities.d.ts +32 -0
  56. package/_types/experimental/actions/getCapabilities.d.ts.map +1 -0
  57. package/_types/experimental/actions/sendCalls.d.ts +56 -0
  58. package/_types/experimental/actions/sendCalls.d.ts.map +1 -0
  59. package/_types/experimental/actions/writeContracts.d.ts +62 -0
  60. package/_types/experimental/actions/writeContracts.d.ts.map +1 -0
  61. package/_types/experimental/decorators/eip5792.d.ts +152 -0
  62. package/_types/experimental/decorators/eip5792.d.ts.map +1 -0
  63. package/_types/experimental/index.d.ts +6 -0
  64. package/_types/experimental/index.d.ts.map +1 -0
  65. package/_types/index.d.ts +1 -1
  66. package/_types/index.d.ts.map +1 -1
  67. package/_types/types/contract.d.ts +1 -1
  68. package/_types/types/contract.d.ts.map +1 -1
  69. package/_types/types/eip1193.d.ts +69 -0
  70. package/_types/types/eip1193.d.ts.map +1 -1
  71. package/_types/utils/formatters/transactionReceipt.d.ts +4 -0
  72. package/_types/utils/formatters/transactionReceipt.d.ts.map +1 -1
  73. package/chains/definitions/degen.ts +1 -0
  74. package/chains/definitions/zkSyncInMemoryNode.ts +2 -0
  75. package/chains/definitions/zkSyncLocalNode.ts +2 -0
  76. package/errors/version.ts +1 -1
  77. package/experimental/actions/getCallsStatus.ts +62 -0
  78. package/experimental/actions/getCapabilities.ts +56 -0
  79. package/experimental/actions/sendCalls.ts +126 -0
  80. package/experimental/actions/writeContracts.ts +115 -0
  81. package/experimental/decorators/eip5792.ts +200 -0
  82. package/experimental/index.ts +28 -0
  83. package/experimental/package.json +6 -0
  84. package/index.ts +6 -1
  85. package/package.json +9 -1
  86. package/types/contract.ts +2 -1
  87. package/types/eip1193.ts +81 -0
  88. package/utils/formatters/transactionReceipt.ts +2 -2
@@ -0,0 +1,200 @@
1
+ import type { Client } from '../../clients/createClient.js'
2
+ import type { Transport } from '../../clients/transports/createTransport.js'
3
+ import type { Account } from '../../types/account.js'
4
+ import type { Chain } from '../../types/chain.js'
5
+ import {
6
+ type GetCallsStatusParameters,
7
+ type GetCallsStatusReturnType,
8
+ getCallsStatus,
9
+ } from '../actions/getCallsStatus.js'
10
+ import {
11
+ type GetCapabilitiesReturnType,
12
+ getCapabilities,
13
+ } from '../actions/getCapabilities.js'
14
+ import {
15
+ type SendCallsParameters,
16
+ type SendCallsReturnType,
17
+ sendCalls,
18
+ } from '../actions/sendCalls.js'
19
+ import {
20
+ type WriteContractsParameters,
21
+ type WriteContractsReturnType,
22
+ writeContracts,
23
+ } from '../actions/writeContracts.js'
24
+
25
+ export type WalletActionsEip5792<
26
+ chain extends Chain | undefined = Chain | undefined,
27
+ account extends Account | undefined = Account | undefined,
28
+ > = {
29
+ /**
30
+ * Returns the status of a call batch that was sent via `sendCalls`.
31
+ *
32
+ * - Docs: https://viem.sh/experimental/actions/getCallsStatus
33
+ * - JSON-RPC Methods: [`wallet_getCallsStatus`](https://eips.ethereum.org/EIPS/eip-5792)
34
+ *
35
+ * @param client - Client to use
36
+ * @returns Status of the calls. {@link GetCallsStatusReturnType}
37
+ *
38
+ * @example
39
+ * import { createWalletClient, custom } from 'viem'
40
+ * import { mainnet } from 'viem/chains'
41
+ * import { walletActionsEip5792 } from 'viem/experimental'
42
+ *
43
+ * const client = createWalletClient({
44
+ * chain: mainnet,
45
+ * transport: custom(window.ethereum),
46
+ * }).extend(walletActionsEip5792())
47
+ *
48
+ * const { receipts, status } = await client.getCallsStatus({ id: '0xdeadbeef' })
49
+ */
50
+ getCallsStatus: (
51
+ parameters: GetCallsStatusParameters,
52
+ ) => Promise<GetCallsStatusReturnType>
53
+ /**
54
+ * Extract capabilities that a connected wallet supports (e.g. paymasters, session keys, etc).
55
+ *
56
+ * - Docs: https://viem.sh/experimental/actions/getCapabilities
57
+ * - JSON-RPC Methods: [`wallet_getCapabilities`](https://eips.ethereum.org/EIPS/eip-5792)
58
+ *
59
+ * @param client - Client to use
60
+ * @returns The wallet's capabilities. {@link GetCapabilitiesReturnType}
61
+ *
62
+ * @example
63
+ * import { createWalletClient, custom } from 'viem'
64
+ * import { mainnet } from 'viem/chains'
65
+ * import { walletActionsEip5792 } from 'viem/experimental'
66
+ *
67
+ * const client = createWalletClient({
68
+ * chain: mainnet,
69
+ * transport: custom(window.ethereum),
70
+ * }).extend(walletActionsEip5792())
71
+ *
72
+ * const capabilities = await client.getCapabilities()
73
+ */
74
+ getCapabilities: () => Promise<GetCapabilitiesReturnType>
75
+ /**
76
+ * Requests the connected wallet to send a batch of calls.
77
+ *
78
+ * - Docs: https://viem.sh/experimental/actions/sendCalls
79
+ * - JSON-RPC Methods: [`wallet_sendCalls`](https://eips.ethereum.org/EIPS/eip-5792)
80
+ *
81
+ * @param client - Client to use
82
+ * @returns Transaction identifier. {@link SendCallsReturnType}
83
+ *
84
+ * @example
85
+ * import { createWalletClient, custom } from 'viem'
86
+ * import { mainnet } from 'viem/chains'
87
+ * import { walletActionsEip5792 } from 'viem/experimental'
88
+ *
89
+ * const client = createWalletClient({
90
+ * chain: mainnet,
91
+ * transport: custom(window.ethereum),
92
+ * }).extend(walletActionsEip5792())
93
+ *
94
+ * const id = await client.sendCalls({
95
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
96
+ * calls: [
97
+ * {
98
+ * data: '0xdeadbeef',
99
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
100
+ * },
101
+ * {
102
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
103
+ * value: 69420n,
104
+ * },
105
+ * ],
106
+ * })
107
+ */
108
+ sendCalls: <chainOverride extends Chain | undefined = undefined>(
109
+ parameters: SendCallsParameters<chain, account, chainOverride>,
110
+ ) => Promise<SendCallsReturnType>
111
+ /**
112
+ * Requests for the wallet to sign and broadcast a batch of write contract calls (transactions) to the network.
113
+ *
114
+ * - Docs: https://viem.sh/experimental/actions/writeContracts
115
+ *
116
+ * @param client - Client to use
117
+ * @param parameters - {@link WriteContractsParameters}
118
+ * @returns Unique identifier for the call batch. {@link WriteContractsReturnType}
119
+ *
120
+ * @example
121
+ * import { createPublicClient, http, parseAbi } from 'viem'
122
+ * import { mainnet } from 'viem/chains'
123
+ * import { writeContracts } from 'viem/experimental'
124
+ *
125
+ * const client = createPublicClient({
126
+ * chain: mainnet,
127
+ * transport: http(),
128
+ * })
129
+ * const abi = parseAbi([
130
+ * 'function approve(address, uint256) returns (bool)',
131
+ * 'function transferFrom(address, address, uint256) returns (bool)',
132
+ * ])
133
+ * const id = await client.writeContracts({
134
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
135
+ * contracts: [
136
+ * {
137
+ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
138
+ * abi,
139
+ * functionName: 'approve',
140
+ * args: ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC', 100n],
141
+ * },
142
+ * {
143
+ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
144
+ * abi,
145
+ * functionName: 'transferFrom',
146
+ * args: [
147
+ * '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
148
+ * '0x0000000000000000000000000000000000000000',
149
+ * 100n
150
+ * ],
151
+ * },
152
+ * ],
153
+ * })
154
+ */
155
+ writeContracts: <
156
+ const contracts extends readonly unknown[],
157
+ chainOverride extends Chain | undefined = undefined,
158
+ >(
159
+ parameters: WriteContractsParameters<
160
+ contracts,
161
+ chain,
162
+ account,
163
+ chainOverride
164
+ >,
165
+ ) => Promise<WriteContractsReturnType>
166
+ }
167
+
168
+ /**
169
+ * A suite of EIP-5792 Wallet Actions.
170
+ *
171
+ * - Docs: https://viem.sh/experimental
172
+ *
173
+ * @example
174
+ * import { createPublicClient, createWalletClient, http } from 'viem'
175
+ * import { mainnet } from 'viem/chains'
176
+ * import { walletActionsEip5792 } from 'viem/experimental'
177
+ *
178
+ * const walletClient = createWalletClient({
179
+ * chain: mainnet,
180
+ * transport: http(),
181
+ * }).extend(walletActionsEip5792())
182
+ *
183
+ * const hash = await walletClient.sendCalls({...})
184
+ */
185
+ export function walletActionsEip5792() {
186
+ return <
187
+ transport extends Transport,
188
+ chain extends Chain | undefined = Chain | undefined,
189
+ account extends Account | undefined = Account | undefined,
190
+ >(
191
+ client: Client<transport, chain, account>,
192
+ ): WalletActionsEip5792<chain, account> => {
193
+ return {
194
+ getCallsStatus: (parameters) => getCallsStatus(client, parameters),
195
+ getCapabilities: () => getCapabilities(client),
196
+ sendCalls: (parameters) => sendCalls(client, parameters),
197
+ writeContracts: (parameters) => writeContracts(client, parameters),
198
+ }
199
+ }
200
+ }
@@ -0,0 +1,28 @@
1
+ export {
2
+ type GetCapabilitiesErrorType,
3
+ type GetCapabilitiesReturnType,
4
+ getCapabilities,
5
+ } from './actions/getCapabilities.js'
6
+ export {
7
+ type SendCallsErrorType,
8
+ type SendCallsParameters,
9
+ type SendCallsReturnType,
10
+ sendCalls,
11
+ } from './actions/sendCalls.js'
12
+ export {
13
+ type GetCallsStatusErrorType,
14
+ type GetCallsStatusParameters,
15
+ type GetCallsStatusReturnType,
16
+ getCallsStatus,
17
+ } from './actions/getCallsStatus.js'
18
+ export {
19
+ type WriteContractsErrorType,
20
+ type WriteContractsParameters,
21
+ type WriteContractsReturnType,
22
+ writeContracts,
23
+ } from './actions/writeContracts.js'
24
+
25
+ export {
26
+ type WalletActionsEip5792,
27
+ walletActionsEip5792,
28
+ } from './decorators/eip5792.js'
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../_types/experimental/index.d.ts",
4
+ "module": "../_esm/experimental/index.js",
5
+ "main": "../_cjs/experimental/index.js"
6
+ }
package/index.ts CHANGED
@@ -999,10 +999,15 @@ export type {
999
999
  RpcSchema,
1000
1000
  RpcSchemaOverride,
1001
1001
  TestRpcSchema,
1002
- WatchAssetParams,
1002
+ WalletCapabilities,
1003
+ WalletCapabilitiesRecord,
1004
+ WalletGetCallsStatusReceipt,
1005
+ WalletGetCallsStatusReturnType,
1006
+ WalletSendCallsParameters,
1003
1007
  WalletPermissionCaveat,
1004
1008
  WalletPermission,
1005
1009
  WalletRpcSchema,
1010
+ WatchAssetParams,
1006
1011
  } from './types/eip1193.js'
1007
1012
  export type { BlobSidecar, BlobSidecars } from './types/eip4844.js'
1008
1013
  export type {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.9.6",
4
+ "version": "2.9.8",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -52,6 +52,11 @@
52
52
  "import": "./_esm/ens/index.js",
53
53
  "default": "./_cjs/ens/index.js"
54
54
  },
55
+ "./experimental": {
56
+ "types": "./_types/experimental/index.d.ts",
57
+ "import": "./_esm/experimental/index.js",
58
+ "default": "./_cjs/experimental/index.js"
59
+ },
55
60
  "./node": {
56
61
  "types": "./_types/node/index.d.ts",
57
62
  "import": "./_esm/node/index.js",
@@ -99,6 +104,9 @@
99
104
  "ens": [
100
105
  "./_types/ens/index.d.ts"
101
106
  ],
107
+ "experimental": [
108
+ "./_types/experimental/index.d.ts"
109
+ ],
102
110
  "node": [
103
111
  "./_types/node/index.d.ts"
104
112
  ],
package/types/contract.ts CHANGED
@@ -209,7 +209,8 @@ export type ContractFunctionParameters<
209
209
  | allFunctionNames // show all options
210
210
  | (functionName extends allFunctionNames ? functionName : never) // infer value
211
211
  args?: (abi extends Abi ? UnionWiden<args> : never) | allArgs | undefined
212
- } & (readonly [] extends allArgs ? {} : { args: Widen<args> })
212
+ } & (readonly [] extends allArgs ? {} : { args: Widen<args> }) &
213
+ GetValue<abi, functionName>
213
214
 
214
215
  export type ContractFunctionReturnType<
215
216
  abi extends Abi | readonly unknown[] = Abi,
package/types/eip1193.ts CHANGED
@@ -107,6 +107,35 @@ export type NetworkSync = {
107
107
  startingBlock: Quantity
108
108
  }
109
109
 
110
+ export type WalletCapabilities = {
111
+ [capability: string]: any
112
+ }
113
+
114
+ export type WalletCapabilitiesRecord<
115
+ capabilities extends WalletCapabilities = WalletCapabilities,
116
+ id extends string | number = Hex,
117
+ > = {
118
+ [chainId in id]: capabilities
119
+ }
120
+
121
+ export type WalletGetCallsStatusReceipt<quantity = Hex, status = Hex> = {
122
+ logs: {
123
+ address: Hex
124
+ data: Hex
125
+ topics: Hex[]
126
+ }[]
127
+ status: status
128
+ blockHash: Hex
129
+ blockNumber: quantity
130
+ gasUsed: quantity
131
+ transactionHash: Hex
132
+ }
133
+
134
+ export type WalletGetCallsStatusReturnType<quantity = Hex, status = Hex> = {
135
+ status: 'PENDING' | 'CONFIRMED'
136
+ receipts?: WalletGetCallsStatusReceipt<quantity, status>[] | undefined
137
+ }
138
+
110
139
  export type WalletPermissionCaveat = {
111
140
  type: string
112
141
  value: any
@@ -120,6 +149,22 @@ export type WalletPermission = {
120
149
  parentCapability: 'eth_accounts' | string
121
150
  }
122
151
 
152
+ export type WalletSendCallsParameters<
153
+ capabilities extends WalletCapabilities = WalletCapabilities,
154
+ chainId extends Hex | number = Hex,
155
+ quantity extends Quantity | bigint = Quantity,
156
+ > = {
157
+ version: string
158
+ chainId: chainId
159
+ from: Address
160
+ calls: {
161
+ to: Address
162
+ data: Hex
163
+ value: quantity
164
+ }[]
165
+ capabilities?: capabilities | undefined
166
+ }
167
+
123
168
  export type WatchAssetParams = {
124
169
  /** Token type. */
125
170
  type: 'ERC20'
@@ -1270,6 +1315,30 @@ export type WalletRpcSchema = [
1270
1315
  Parameters: [chain: AddEthereumChainParameter]
1271
1316
  ReturnType: null
1272
1317
  },
1318
+ /**
1319
+ * @description Returns the status of a call batch that was sent via `wallet_sendCalls`.
1320
+ * @link https://eips.ethereum.org/EIPS/eip-5792
1321
+ * @example
1322
+ * provider.request({ method: 'wallet_getCallsStatus' })
1323
+ * // => { ... }
1324
+ */
1325
+ {
1326
+ Method: 'wallet_getCallsStatus'
1327
+ Parameters?: string
1328
+ ReturnType: WalletGetCallsStatusReturnType
1329
+ },
1330
+ /**
1331
+ * @description Gets the connected wallet's capabilities.
1332
+ * @link https://eips.ethereum.org/EIPS/eip-5792
1333
+ * @example
1334
+ * provider.request({ method: 'wallet_getCapabilities' })
1335
+ * // => { ... }
1336
+ */
1337
+ {
1338
+ Method: 'wallet_getCapabilities'
1339
+ Parameters?: undefined
1340
+ ReturnType: Prettify<WalletCapabilitiesRecord>
1341
+ },
1273
1342
  /**
1274
1343
  * @description Gets the wallets current permissions.
1275
1344
  * @link https://eips.ethereum.org/EIPS/eip-2255
@@ -1294,6 +1363,18 @@ export type WalletRpcSchema = [
1294
1363
  Parameters: [permissions: { eth_accounts: Record<string, any> }]
1295
1364
  ReturnType: WalletPermission[]
1296
1365
  },
1366
+ /**
1367
+ * @description Requests the connected wallet to send a batch of calls.
1368
+ * @link https://eips.ethereum.org/EIPS/eip-5792
1369
+ * @example
1370
+ * provider.request({ method: 'wallet_sendCalls' })
1371
+ * // => { ... }
1372
+ */
1373
+ {
1374
+ Method: 'wallet_sendCalls'
1375
+ Parameters?: WalletSendCallsParameters
1376
+ ReturnType: string
1377
+ },
1297
1378
  /**
1298
1379
  * @description Switch the wallet to the given Ethereum chain.
1299
1380
  * @link https://eips.ethereum.org/EIPS/eip-3326
@@ -20,7 +20,7 @@ export type FormattedTransactionReceipt<
20
20
  TransactionReceipt
21
21
  >
22
22
 
23
- const statuses = {
23
+ export const receiptStatuses = {
24
24
  '0x0': 'reverted',
25
25
  '0x1': 'success',
26
26
  } as const
@@ -55,7 +55,7 @@ export function formatTransactionReceipt(
55
55
  ? hexToNumber(transactionReceipt.transactionIndex)
56
56
  : null,
57
57
  status: transactionReceipt.status
58
- ? statuses[transactionReceipt.status]
58
+ ? receiptStatuses[transactionReceipt.status]
59
59
  : null,
60
60
  type: transactionReceipt.type
61
61
  ? transactionType[