viem 2.9.6 → 2.9.7
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 +10 -0
- package/_cjs/chains/definitions/degen.js +1 -0
- package/_cjs/chains/definitions/degen.js.map +1 -1
- package/_cjs/chains/definitions/zkSyncInMemoryNode.js +2 -0
- package/_cjs/chains/definitions/zkSyncInMemoryNode.js.map +1 -1
- package/_cjs/chains/definitions/zkSyncLocalNode.js +2 -0
- package/_cjs/chains/definitions/zkSyncLocalNode.js.map +1 -1
- 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/index.js.map +1 -1
- package/_cjs/utils/formatters/transactionReceipt.js +3 -3
- package/_cjs/utils/formatters/transactionReceipt.js.map +1 -1
- package/_esm/chains/definitions/degen.js +1 -0
- package/_esm/chains/definitions/degen.js.map +1 -1
- package/_esm/chains/definitions/zkSyncInMemoryNode.js +2 -0
- package/_esm/chains/definitions/zkSyncInMemoryNode.js.map +1 -1
- package/_esm/chains/definitions/zkSyncLocalNode.js +2 -0
- package/_esm/chains/definitions/zkSyncLocalNode.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/index.js.map +1 -1
- package/_esm/utils/formatters/transactionReceipt.js +2 -2
- package/_esm/utils/formatters/transactionReceipt.js.map +1 -1
- package/_types/chains/definitions/degen.d.ts +1 -0
- package/_types/chains/definitions/degen.d.ts.map +1 -1
- package/_types/chains/definitions/zkSyncInMemoryNode.d.ts +1278 -3
- package/_types/chains/definitions/zkSyncInMemoryNode.d.ts.map +1 -1
- package/_types/chains/definitions/zkSyncLocalNode.d.ts +1278 -3
- package/_types/chains/definitions/zkSyncLocalNode.d.ts.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/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- 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/chains/definitions/degen.ts +1 -0
- package/chains/definitions/zkSyncInMemoryNode.ts +2 -0
- package/chains/definitions/zkSyncLocalNode.ts +2 -0
- 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/index.ts +6 -1
- package/package.json +9 -1
- package/types/eip1193.ts +81 -0
- package/utils/formatters/transactionReceipt.ts +2 -2
@@ -1,6 +1,8 @@
|
|
1
1
|
import { defineChain } from '../../utils/chain/defineChain.js'
|
2
|
+
import { chainConfig } from '../../zksync/chainConfig.js'
|
2
3
|
|
3
4
|
export const zkSyncInMemoryNode = /*#__PURE__*/ defineChain({
|
5
|
+
...chainConfig,
|
4
6
|
id: 260,
|
5
7
|
name: 'zkSync InMemory Node',
|
6
8
|
network: 'zksync-in-memory-node',
|
@@ -1,6 +1,8 @@
|
|
1
1
|
import { defineChain } from '../../utils/chain/defineChain.js'
|
2
|
+
import { chainConfig } from '../../zksync/chainConfig.js'
|
2
3
|
|
3
4
|
export const zkSyncLocalNode = /*#__PURE__*/ defineChain({
|
5
|
+
...chainConfig,
|
4
6
|
id: 270,
|
5
7
|
name: 'zkSync CLI Local Node',
|
6
8
|
network: 'zksync-cli-local-node',
|
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '2.9.
|
1
|
+
export const version = '2.9.7'
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import type { Client } from '../../clients/createClient.js'
|
2
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
3
|
+
import type { ErrorType } from '../../errors/utils.js'
|
4
|
+
import type { Account } from '../../types/account.js'
|
5
|
+
import type { Chain } from '../../types/chain.js'
|
6
|
+
import type { WalletGetCallsStatusReturnType } from '../../types/eip1193.js'
|
7
|
+
import type { Prettify } from '../../types/utils.js'
|
8
|
+
import type { RequestErrorType } from '../../utils/buildRequest.js'
|
9
|
+
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
10
|
+
import { receiptStatuses } from '../../utils/formatters/transactionReceipt.js'
|
11
|
+
|
12
|
+
export type GetCallsStatusParameters = { id: string }
|
13
|
+
|
14
|
+
export type GetCallsStatusReturnType = Prettify<
|
15
|
+
WalletGetCallsStatusReturnType<bigint, 'success' | 'reverted'>
|
16
|
+
>
|
17
|
+
|
18
|
+
export type GetCallsStatusErrorType = RequestErrorType | ErrorType
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Returns the status of a call batch that was sent via `sendCalls`.
|
22
|
+
*
|
23
|
+
* - Docs: https://viem.sh/eip5792/actions/getCallsStatus
|
24
|
+
* - JSON-RPC Methods: [`wallet_getCallsStatus`](https://eips.ethereum.org/EIPS/eip-5792)
|
25
|
+
*
|
26
|
+
* @param client - Client to use
|
27
|
+
* @returns Status of the calls. {@link GetCallsStatusReturnType}
|
28
|
+
*
|
29
|
+
* @example
|
30
|
+
* import { createWalletClient, custom } from 'viem'
|
31
|
+
* import { mainnet } from 'viem/chains'
|
32
|
+
* import { getCallsStatus } from 'viem/wallet'
|
33
|
+
*
|
34
|
+
* const client = createWalletClient({
|
35
|
+
* chain: mainnet,
|
36
|
+
* transport: custom(window.ethereum),
|
37
|
+
* })
|
38
|
+
* const { receipts, status } = await getCallsStatus(client, { id: '0xdeadbeef' })
|
39
|
+
*/
|
40
|
+
export async function getCallsStatus<
|
41
|
+
chain extends Chain | undefined,
|
42
|
+
account extends Account | undefined = undefined,
|
43
|
+
>(
|
44
|
+
client: Client<Transport, chain, account>,
|
45
|
+
parameters: GetCallsStatusParameters,
|
46
|
+
): Promise<GetCallsStatusReturnType> {
|
47
|
+
const { id } = parameters
|
48
|
+
const { receipts, status } = await client.request({
|
49
|
+
method: 'wallet_getCallsStatus',
|
50
|
+
params: id,
|
51
|
+
})
|
52
|
+
return {
|
53
|
+
status,
|
54
|
+
receipts:
|
55
|
+
receipts?.map((receipt) => ({
|
56
|
+
...receipt,
|
57
|
+
blockNumber: hexToBigInt(receipt.blockNumber),
|
58
|
+
gasUsed: hexToBigInt(receipt.gasUsed),
|
59
|
+
status: receiptStatuses[receipt.status as '0x0' | '0x1'],
|
60
|
+
})) ?? [],
|
61
|
+
}
|
62
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import type { Client } from '../../clients/createClient.js'
|
2
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
3
|
+
import type { ErrorType } from '../../errors/utils.js'
|
4
|
+
import type { Account } from '../../types/account.js'
|
5
|
+
import type { Chain } from '../../types/chain.js'
|
6
|
+
import type {
|
7
|
+
WalletCapabilities,
|
8
|
+
WalletCapabilitiesRecord,
|
9
|
+
} from '../../types/eip1193.js'
|
10
|
+
import type { Prettify } from '../../types/utils.js'
|
11
|
+
import type { RequestErrorType } from '../../utils/buildRequest.js'
|
12
|
+
|
13
|
+
export type GetCapabilitiesReturnType = Prettify<
|
14
|
+
WalletCapabilitiesRecord<WalletCapabilities, number>
|
15
|
+
>
|
16
|
+
|
17
|
+
export type GetCapabilitiesErrorType = RequestErrorType | ErrorType
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Extract capabilities that a connected wallet supports (e.g. paymasters, session keys, etc).
|
21
|
+
*
|
22
|
+
* - Docs: https://viem.sh/eip5792/actions/getCapabilities
|
23
|
+
* - JSON-RPC Methods: [`wallet_getCapabilities`](https://eips.ethereum.org/EIPS/eip-5792)
|
24
|
+
*
|
25
|
+
* @param client - Client to use
|
26
|
+
* @returns The wallet's capabilities. {@link GetCapabilitiesReturnType}
|
27
|
+
*
|
28
|
+
* @example
|
29
|
+
* import { createWalletClient, custom } from 'viem'
|
30
|
+
* import { mainnet } from 'viem/chains'
|
31
|
+
* import { getCapabilities } from 'viem/wallet'
|
32
|
+
*
|
33
|
+
* const client = createWalletClient({
|
34
|
+
* chain: mainnet,
|
35
|
+
* transport: custom(window.ethereum),
|
36
|
+
* })
|
37
|
+
* const capabilities = await getCapabilities(client)
|
38
|
+
*/
|
39
|
+
export async function getCapabilities<
|
40
|
+
chain extends Chain | undefined,
|
41
|
+
account extends Account | undefined = undefined,
|
42
|
+
>(
|
43
|
+
client: Client<Transport, chain, account>,
|
44
|
+
): Promise<GetCapabilitiesReturnType> {
|
45
|
+
const capabilities_raw = await client.request({
|
46
|
+
method: 'wallet_getCapabilities',
|
47
|
+
})
|
48
|
+
|
49
|
+
const capabilities = {} as WalletCapabilitiesRecord<
|
50
|
+
WalletCapabilities,
|
51
|
+
number
|
52
|
+
>
|
53
|
+
for (const [key, value] of Object.entries(capabilities_raw))
|
54
|
+
capabilities[Number(key)] = value
|
55
|
+
return capabilities
|
56
|
+
}
|
@@ -0,0 +1,126 @@
|
|
1
|
+
import type { Client } from '../../clients/createClient.js'
|
2
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
3
|
+
import { AccountNotFoundError } from '../../errors/account.js'
|
4
|
+
import type { BaseError } from '../../errors/base.js'
|
5
|
+
import { ChainNotFoundError } from '../../errors/chain.js'
|
6
|
+
import type { ErrorType } from '../../errors/utils.js'
|
7
|
+
import type { Account, GetAccountParameter } from '../../types/account.js'
|
8
|
+
import type { Chain, GetChainParameter } from '../../types/chain.js'
|
9
|
+
import type {
|
10
|
+
WalletCapabilities,
|
11
|
+
WalletSendCallsParameters,
|
12
|
+
} from '../../types/eip1193.js'
|
13
|
+
import type { Hex } from '../../types/misc.js'
|
14
|
+
import type { OneOf } from '../../types/utils.js'
|
15
|
+
import { parseAccount } from '../../utils/accounts.js'
|
16
|
+
import type { RequestErrorType } from '../../utils/buildRequest.js'
|
17
|
+
import { numberToHex } from '../../utils/encoding/toHex.js'
|
18
|
+
import { getTransactionError } from '../../utils/index.js'
|
19
|
+
|
20
|
+
export type SendCallsParameters<
|
21
|
+
chain extends Chain | undefined = Chain | undefined,
|
22
|
+
account extends Account | undefined = Account | undefined,
|
23
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
24
|
+
> = {
|
25
|
+
calls: OneOf<
|
26
|
+
| {
|
27
|
+
to: Hex
|
28
|
+
data?: Hex
|
29
|
+
value?: bigint
|
30
|
+
}
|
31
|
+
| {
|
32
|
+
data: Hex
|
33
|
+
}
|
34
|
+
>[]
|
35
|
+
capabilities?:
|
36
|
+
| WalletSendCallsParameters<WalletCapabilities>['capabilities']
|
37
|
+
| undefined
|
38
|
+
version?: WalletSendCallsParameters['version'] | undefined
|
39
|
+
} & GetAccountParameter<account> &
|
40
|
+
GetChainParameter<chain, chainOverride>
|
41
|
+
|
42
|
+
export type SendCallsReturnType = string
|
43
|
+
|
44
|
+
export type SendCallsErrorType = RequestErrorType | ErrorType
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Requests the connected wallet to send a batch of calls.
|
48
|
+
*
|
49
|
+
* - Docs: https://viem.sh/eip5792/actions/sendCalls
|
50
|
+
* - JSON-RPC Methods: [`wallet_sendCalls`](https://eips.ethereum.org/EIPS/eip-5792)
|
51
|
+
*
|
52
|
+
* @param client - Client to use
|
53
|
+
* @returns Transaction identifier. {@link SendCallsReturnType}
|
54
|
+
*
|
55
|
+
* @example
|
56
|
+
* import { createWalletClient, custom } from 'viem'
|
57
|
+
* import { mainnet } from 'viem/chains'
|
58
|
+
* import { sendCalls } from 'viem/wallet'
|
59
|
+
*
|
60
|
+
* const client = createWalletClient({
|
61
|
+
* chain: mainnet,
|
62
|
+
* transport: custom(window.ethereum),
|
63
|
+
* })
|
64
|
+
* const id = await sendCalls(client, {
|
65
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
66
|
+
* calls: [
|
67
|
+
* {
|
68
|
+
* data: '0xdeadbeef',
|
69
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
70
|
+
* },
|
71
|
+
* {
|
72
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
73
|
+
* value: 69420n,
|
74
|
+
* },
|
75
|
+
* ],
|
76
|
+
* })
|
77
|
+
*/
|
78
|
+
export async function sendCalls<
|
79
|
+
chain extends Chain | undefined,
|
80
|
+
account extends Account | undefined = undefined,
|
81
|
+
chainOverride extends Chain | undefined = undefined,
|
82
|
+
>(
|
83
|
+
client: Client<Transport, chain, account>,
|
84
|
+
parameters: SendCallsParameters<chain, account, chainOverride>,
|
85
|
+
): Promise<SendCallsReturnType> {
|
86
|
+
const {
|
87
|
+
account: account_ = client.account,
|
88
|
+
calls,
|
89
|
+
capabilities,
|
90
|
+
chain = client.chain,
|
91
|
+
version = '1.0',
|
92
|
+
} = parameters
|
93
|
+
|
94
|
+
if (!account_)
|
95
|
+
throw new AccountNotFoundError({
|
96
|
+
docsPath: '/eip5792/actions/sendCalls',
|
97
|
+
})
|
98
|
+
const account = parseAccount(account_)
|
99
|
+
|
100
|
+
if (!chain) throw new ChainNotFoundError()
|
101
|
+
|
102
|
+
try {
|
103
|
+
return await client.request(
|
104
|
+
{
|
105
|
+
method: 'wallet_sendCalls',
|
106
|
+
params: {
|
107
|
+
calls: calls.map((call) => ({
|
108
|
+
...call,
|
109
|
+
value: call.value ? numberToHex(call.value) : undefined,
|
110
|
+
})) as any,
|
111
|
+
capabilities,
|
112
|
+
chainId: numberToHex(chain!.id),
|
113
|
+
from: account.address,
|
114
|
+
version,
|
115
|
+
},
|
116
|
+
},
|
117
|
+
{ retryCount: 0 },
|
118
|
+
)
|
119
|
+
} catch (err) {
|
120
|
+
throw getTransactionError(err as BaseError, {
|
121
|
+
...parameters,
|
122
|
+
account,
|
123
|
+
chain: parameters.chain!,
|
124
|
+
})
|
125
|
+
}
|
126
|
+
}
|
@@ -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/index.ts
CHANGED
@@ -999,10 +999,15 @@ export type {
|
|
999
999
|
RpcSchema,
|
1000
1000
|
RpcSchemaOverride,
|
1001
1001
|
TestRpcSchema,
|
1002
|
-
|
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.
|
4
|
+
"version": "2.9.7",
|
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/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[
|