viem 0.0.0-main.20240402T193906 → 0.0.0-main.20240402T203246
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/_cjs/errors/version.js +1 -1
- package/_cjs/experimental/actions/getCallsStatus.js +23 -0
- package/_cjs/experimental/actions/getCallsStatus.js.map +1 -0
- package/_cjs/experimental/actions/getCapabilities.js +14 -0
- package/_cjs/experimental/actions/getCapabilities.js.map +1 -0
- package/_cjs/experimental/actions/sendCalls.js +42 -0
- package/_cjs/experimental/actions/sendCalls.js.map +1 -0
- package/_cjs/experimental/decorators/eip5792.js +17 -0
- package/_cjs/experimental/decorators/eip5792.js.map +1 -0
- package/_cjs/experimental/index.js +12 -0
- package/_cjs/experimental/index.js.map +1 -0
- package/_cjs/utils/formatters/transactionReceipt.js +3 -3
- package/_cjs/utils/formatters/transactionReceipt.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/experimental/actions/getCallsStatus.js +39 -0
- package/_esm/experimental/actions/getCallsStatus.js.map +1 -0
- package/_esm/experimental/actions/getCapabilities.js +30 -0
- package/_esm/experimental/actions/getCapabilities.js.map +1 -0
- package/_esm/experimental/actions/sendCalls.js +70 -0
- package/_esm/experimental/actions/sendCalls.js.map +1 -0
- package/_esm/experimental/decorators/eip5792.js +30 -0
- package/_esm/experimental/decorators/eip5792.js.map +1 -0
- package/_esm/experimental/index.js +5 -0
- package/_esm/experimental/index.js.map +1 -0
- package/_esm/utils/formatters/transactionReceipt.js +2 -2
- package/_esm/utils/formatters/transactionReceipt.js.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/experimental/actions/getCallsStatus.d.ts +35 -0
- package/_types/experimental/actions/getCallsStatus.d.ts.map +1 -0
- package/_types/experimental/actions/getCapabilities.d.ts +32 -0
- package/_types/experimental/actions/getCapabilities.d.ts.map +1 -0
- package/_types/experimental/actions/sendCalls.d.ts +56 -0
- package/_types/experimental/actions/sendCalls.d.ts.map +1 -0
- package/_types/experimental/decorators/eip5792.d.ts +106 -0
- package/_types/experimental/decorators/eip5792.d.ts.map +1 -0
- package/_types/experimental/index.d.ts +5 -0
- package/_types/experimental/index.d.ts.map +1 -0
- package/_types/types/eip1193.d.ts +69 -0
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/utils/formatters/transactionReceipt.d.ts +4 -0
- package/_types/utils/formatters/transactionReceipt.d.ts.map +1 -1
- package/errors/version.ts +1 -1
- package/experimental/actions/getCallsStatus.ts +62 -0
- package/experimental/actions/getCapabilities.ts +56 -0
- package/experimental/actions/sendCalls.ts +126 -0
- package/experimental/decorators/eip5792.ts +139 -0
- package/experimental/index.ts +22 -0
- package/experimental/package.json +6 -0
- package/package.json +9 -1
- package/types/eip1193.ts +81 -0
- package/utils/formatters/transactionReceipt.ts +2 -2
@@ -0,0 +1,139 @@
|
|
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
|
+
|
20
|
+
export type WalletActionsEip5792<
|
21
|
+
chain extends Chain | undefined = Chain | undefined,
|
22
|
+
account extends Account | undefined = Account | undefined,
|
23
|
+
> = {
|
24
|
+
/**
|
25
|
+
* Returns the status of a call batch that was sent via `sendCalls`.
|
26
|
+
*
|
27
|
+
* - Docs: https://viem.sh/eip5792/actions/getCallsStatus
|
28
|
+
* - JSON-RPC Methods: [`wallet_getCallsStatus`](https://eips.ethereum.org/EIPS/eip-5792)
|
29
|
+
*
|
30
|
+
* @param client - Client to use
|
31
|
+
* @returns Status of the calls. {@link GetCallsStatusReturnType}
|
32
|
+
*
|
33
|
+
* @example
|
34
|
+
* import { createWalletClient, custom } from 'viem'
|
35
|
+
* import { mainnet } from 'viem/chains'
|
36
|
+
* import { walletActionsEip5792 } from 'viem/experimental'
|
37
|
+
*
|
38
|
+
* const client = createWalletClient({
|
39
|
+
* chain: mainnet,
|
40
|
+
* transport: custom(window.ethereum),
|
41
|
+
* }).extend(walletActionsEip5792())
|
42
|
+
*
|
43
|
+
* const { receipts, status } = await client.getCallsStatus({ id: '0xdeadbeef' })
|
44
|
+
*/
|
45
|
+
getCallsStatus: (
|
46
|
+
parameters: GetCallsStatusParameters,
|
47
|
+
) => Promise<GetCallsStatusReturnType>
|
48
|
+
/**
|
49
|
+
* Extract capabilities that a connected wallet supports (e.g. paymasters, session keys, etc).
|
50
|
+
*
|
51
|
+
* - Docs: https://viem.sh/eip5792/actions/getCapabilities
|
52
|
+
* - JSON-RPC Methods: [`wallet_getCapabilities`](https://eips.ethereum.org/EIPS/eip-5792)
|
53
|
+
*
|
54
|
+
* @param client - Client to use
|
55
|
+
* @returns The wallet's capabilities. {@link GetCapabilitiesReturnType}
|
56
|
+
*
|
57
|
+
* @example
|
58
|
+
* import { createWalletClient, custom } from 'viem'
|
59
|
+
* import { mainnet } from 'viem/chains'
|
60
|
+
* import { walletActionsEip5792 } from 'viem/experimental'
|
61
|
+
*
|
62
|
+
* const client = createWalletClient({
|
63
|
+
* chain: mainnet,
|
64
|
+
* transport: custom(window.ethereum),
|
65
|
+
* }).extend(walletActionsEip5792())
|
66
|
+
*
|
67
|
+
* const capabilities = await client.getCapabilities()
|
68
|
+
*/
|
69
|
+
getCapabilities: () => Promise<GetCapabilitiesReturnType>
|
70
|
+
/**
|
71
|
+
* Requests the connected wallet to send a batch of calls.
|
72
|
+
*
|
73
|
+
* - Docs: https://viem.sh/eip5792/actions/sendCalls
|
74
|
+
* - JSON-RPC Methods: [`wallet_sendCalls`](https://eips.ethereum.org/EIPS/eip-5792)
|
75
|
+
*
|
76
|
+
* @param client - Client to use
|
77
|
+
* @returns Transaction identifier. {@link SendCallsReturnType}
|
78
|
+
*
|
79
|
+
* @example
|
80
|
+
* import { createWalletClient, custom } from 'viem'
|
81
|
+
* import { mainnet } from 'viem/chains'
|
82
|
+
* import { walletActionsEip5792 } from 'viem/experimental'
|
83
|
+
*
|
84
|
+
* const client = createWalletClient({
|
85
|
+
* chain: mainnet,
|
86
|
+
* transport: custom(window.ethereum),
|
87
|
+
* }).extend(walletActionsEip5792())
|
88
|
+
*
|
89
|
+
* const id = await client.sendCalls({
|
90
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
91
|
+
* calls: [
|
92
|
+
* {
|
93
|
+
* data: '0xdeadbeef',
|
94
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
95
|
+
* },
|
96
|
+
* {
|
97
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
98
|
+
* value: 69420n,
|
99
|
+
* },
|
100
|
+
* ],
|
101
|
+
* })
|
102
|
+
*/
|
103
|
+
sendCalls: <chainOverride extends Chain | undefined = undefined>(
|
104
|
+
parameters: SendCallsParameters<chain, account, chainOverride>,
|
105
|
+
) => Promise<SendCallsReturnType>
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* A suite of EIP-5792 Wallet Actions.
|
110
|
+
*
|
111
|
+
* - Docs: https://viem.sh/eip5792
|
112
|
+
*
|
113
|
+
* @example
|
114
|
+
* import { createPublicClient, createWalletClient, http } from 'viem'
|
115
|
+
* import { mainnet } from 'viem/chains'
|
116
|
+
* import { walletActionsEip5792 } from 'viem/experimental'
|
117
|
+
*
|
118
|
+
* const walletClient = createWalletClient({
|
119
|
+
* chain: mainnet,
|
120
|
+
* transport: http(),
|
121
|
+
* }).extend(walletActionsEip5792())
|
122
|
+
*
|
123
|
+
* const hash = await walletClient.sendCalls({...})
|
124
|
+
*/
|
125
|
+
export function walletActionsEip5792() {
|
126
|
+
return <
|
127
|
+
transport extends Transport,
|
128
|
+
chain extends Chain | undefined = Chain | undefined,
|
129
|
+
account extends Account | undefined = Account | undefined,
|
130
|
+
>(
|
131
|
+
client: Client<transport, chain, account>,
|
132
|
+
): WalletActionsEip5792<chain, account> => {
|
133
|
+
return {
|
134
|
+
getCallsStatus: (parameters) => getCallsStatus(client, parameters),
|
135
|
+
getCapabilities: () => getCapabilities(client),
|
136
|
+
sendCalls: (parameters) => sendCalls(client, parameters),
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
@@ -0,0 +1,22 @@
|
|
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
|
+
|
19
|
+
export {
|
20
|
+
type WalletActionsEip5792,
|
21
|
+
walletActionsEip5792,
|
22
|
+
} from './decorators/eip5792.js'
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "viem",
|
3
3
|
"description": "TypeScript Interface for Ethereum",
|
4
|
-
"version": "0.0.0-main.
|
4
|
+
"version": "0.0.0-main.20240402T203246",
|
5
5
|
"type": "module",
|
6
6
|
"main": "./_cjs/index.js",
|
7
7
|
"module": "./_esm/index.js",
|
@@ -53,6 +53,11 @@
|
|
53
53
|
"import": "./_esm/ens/index.js",
|
54
54
|
"default": "./_cjs/ens/index.js"
|
55
55
|
},
|
56
|
+
"./experimental": {
|
57
|
+
"types": "./_types/experimental/index.d.ts",
|
58
|
+
"import": "./_esm/experimental/index.js",
|
59
|
+
"default": "./_cjs/experimental/index.js"
|
60
|
+
},
|
56
61
|
"./node": {
|
57
62
|
"types": "./_types/node/index.d.ts",
|
58
63
|
"import": "./_esm/node/index.js",
|
@@ -100,6 +105,9 @@
|
|
100
105
|
"ens": [
|
101
106
|
"./_types/ens/index.d.ts"
|
102
107
|
],
|
108
|
+
"experimental": [
|
109
|
+
"./_types/experimental/index.d.ts"
|
110
|
+
],
|
103
111
|
"node": [
|
104
112
|
"./_types/node/index.d.ts"
|
105
113
|
],
|
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>[]
|
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
|
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
|
-
?
|
58
|
+
? receiptStatuses[transactionReceipt.status]
|
59
59
|
: null,
|
60
60
|
type: transactionReceipt.type
|
61
61
|
? transactionType[
|