viem 2.9.5 → 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 +22 -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 +27 -0
- package/_cjs/chains/definitions/degen.js.map +1 -0
- 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/chains/index.js +6 -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/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/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/formatters/transactionReceipt.js +3 -3
- package/_cjs/utils/formatters/transactionReceipt.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 +24 -0
- package/_esm/chains/definitions/degen.js.map +1 -0
- 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/chains/index.js +1 -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/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/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/formatters/transactionReceipt.js +2 -2
- package/_esm/utils/formatters/transactionReceipt.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/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 +37 -0
- package/_types/chains/definitions/degen.d.ts.map +1 -0
- 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/chains/index.d.ts +1 -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/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/chain.d.ts +2 -1
- package/_types/types/chain.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/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/formatters/transactionReceipt.d.ts +4 -0
- package/_types/utils/formatters/transactionReceipt.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/celo/chainConfig.ts +2 -0
- package/celo/fees.ts +92 -0
- package/chains/definitions/degen.ts +24 -0
- package/chains/definitions/zkSyncInMemoryNode.ts +2 -0
- package/chains/definitions/zkSyncLocalNode.ts +2 -0
- package/chains/index.ts +1 -0
- package/clients/transports/http.ts +5 -3
- 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/chain.ts +7 -3
- package/types/eip1193.ts +81 -0
- package/utils/address/getAddress.ts +2 -1
- package/utils/address/isAddress.ts +3 -1
- package/utils/formatters/transactionReceipt.ts +2 -2
- package/utils/rpc/http.ts +17 -12
@@ -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/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
|
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
|
@@ -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 = (() => {
|
@@ -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[
|
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({
|